import { Injectable } from '@angular/core';
import { map, Observable } from 'rxjs';
import { HttpRequestService } from '../resources/http-request.service';
import { RequestDeleteCatalogFailure, RequestFormCatalogFailure, ResponseDataCatalogFailure, ResponseDataGetCatalogFailure } from 'src/app/interfaces/failure-analysis/catalog-failure.interface'
import { ResponseData } from 'src/app/interfaces/response-data';
import { ResponseDataGetEquipmentByFailure } from 'src/app/interfaces/failure-analysis/statistical-analysis';

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

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

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

  public getCatalogFailureActives(idUser: string): Observable<ResponseDataGetCatalogFailure> {
    return this._httpRequestService.getQuery(`${this._url}/get-list-failure-actives`).pipe(map((data: any) => data))
  }

  public getCatalogFailureById(idFailure: string): Observable<ResponseDataCatalogFailure> {
    return this._httpRequestService.getQuery(`${this._url}/get-list-failure-by-id/${idFailure}`).pipe(map((data: any) => data))
  }

  public getEquipmentByFailure(idFailure: string): Observable<ResponseDataGetEquipmentByFailure>{
    return this._httpRequestService.getQuery(`${this._url}/get-equipment-by-failure/${idFailure}`).pipe(map((data: any) => data))
  }

  public getCatalogFailureByClassification(classification: string): Observable<ResponseDataGetCatalogFailure> {
    return this._httpRequestService.getQuery(`${this._url}/get-list-failure-by-classification/${classification}`).pipe(map((data: any) => data))
  }

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

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

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