import { Injectable } from '@angular/core';
import { Subject } from 'rxjs';

@Injectable({ providedIn: 'root' })
export class ErrorService {
  private errors = new Subject<{ code: number; message: string; invalidProperties: string; logout: boolean }>();
  private recovery = new Subject<boolean>();

  constructor() {}

  public addErrors = (code: number, errors: string, invalidProperties: string, logout = false): void =>
    // tslint:disable-next-line: semicolon
    this.errors.next({ code: code, message: errors, invalidProperties: invalidProperties, logout: logout });

  public getErrors = () => this.errors.asObservable();

  public addRecovery = (positive: boolean): void => this.recovery.next(positive);

  public recovery$ = () => this.recovery.asObservable();
}
