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

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

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

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

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

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

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