import { Injectable } from '@angular/core';
import { map, Observable } from 'rxjs';
import { DeleteFormFailure, FormFailure, FormFailureEquipment, ResponseDataGet, ResponseDataGetFailureByEquipment } from 'src/app/interfaces/ANFA/failure.interface';
import { ResponseData } from 'src/app/interfaces/response-data';
import { HttpRequestService } from '../resources/http-request.service';

@Injectable({
  providedIn: 'root'
})
export class FailureService {

  private _url: string;
  constructor( private _httpRequestService: HttpRequestService ) {
    this._url = 'failure-analysis';
  }

  public getFailure(): Observable<ResponseDataGet> {
    return this._httpRequestService.getQuery(`${this._url}/get-failure`).pipe(map((data: any) => data));
  }

  public getFailureByEquipment(response: FormFailureEquipment): Observable<ResponseDataGetFailureByEquipment> {
    return this._httpRequestService.postQuery(`${this._url}/get-failure-by-equipment`, response).pipe(map((data: any) => data));
  }

  public registerFailure(response:FormFailure): Observable<ResponseData> {
    return this._httpRequestService.postQuery(`${this._url}/register-failure`, response).pipe(map((data:any) => data));
  }

  public updateFailure(response:FormFailure): Observable<ResponseData> {
    return this._httpRequestService.postQuery(`${this._url}/update-failure`, response).pipe(map((data:any) => data));
  }

  public deteleFailure(response:DeleteFormFailure): Observable<ResponseData> {
    return this._httpRequestService.postQuery(`${this._url}/delete-failure`, response).pipe(map((data:any) => data));
  }
}
