import { Injectable } from '@angular/core';
import { HttpRequestService } from '../http-request.service';
import { map, Observable } from 'rxjs';
import { RequestDeleteCatalogFailure, RequestFormCatalogFailure, ResponseDataCatalogFailure, ResponseDataGetCatalogFailure } from '../../interfaces/failure-analysis/catalog-failure.interface';
import { ResponseDataGetEquipmentByFailure } from '../../interfaces/failure-analysis/statistical-analysis';
import { ResponseData } from '../resources.service';
import { ResponseDataDetailsHistory, ResponseDataGetAlarmEmissionFromFailures, ResponseDataGetFailureLog, ResponseDataGetHistoryFailureEquipment } from '../../interfaces/failure-analysis/failure.interface';
import { ActiveSymptomsListResponse, RequestDataDeleteSymtom, RequestDataFormSymptom, RequestGenerateMTBF, ResponseDataGenerateMTBF, ResponseDataGetSymptomList, ResponseDataSymptomList } from '../../interfaces/failure-analysis/symptom.interface';

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

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

  public getCatalogFailure(user: string, line: number): Observable<ResponseDataGetCatalogFailure> {
    return this._httpRequestService.getQuery(`${this._url}/get-list-failure/${user}/${line}`).pipe(map((data: any) => data))
  }
  public getCatalogFailureActives(user: string, line: number): Observable<ResponseDataGetCatalogFailure> {
    return this._httpRequestService.getQuery(`${this._url}/get-list-failure-actives/${user}/${line}`).pipe(map((data: any) => data))
  }
  public getCatalogFailureById(idFailure: string, user: string, line: number): Observable<ResponseDataCatalogFailure> {
    return this._httpRequestService.getQuery(`${this._url}/get-list-failure-by-id/${idFailure}/${user}/${line}`).pipe(map((data: any) => data))
  }
  public getEquipmentByFailure(idFailure: string, user: string, line: number): Observable<ResponseDataGetEquipmentByFailure>{
    return this._httpRequestService.getQuery(`${this._url}/get-equipment-by-failure/${idFailure}/${user}/${line}`).pipe(map((data: any) => data))
  }
  public getCatalogFailureByClassification(classification: string, user: string, line: number): Observable<ResponseDataGetCatalogFailure> {
    return this._httpRequestService.getQuery(`${this._url}/get-list-failure-by-classification/${classification}/${user}/${line}`).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))
  }


  public getFailure(user: string, line: number): Observable<ResponseDataGetFailureLog> {
    return this._httpRequestService.getQuery(`${this._url}/get-failure-log/${user}/${line}`).pipe(map((data: any) => data));
  }
  public getHistoryFailureEquipment(codeEquipment: string, user: string, line: number): Observable<ResponseDataGetHistoryFailureEquipment> {
    return this._httpRequestService.getQuery(`${this._url}/get-history-failure-equipment/${codeEquipment}/${user}/${line}`).pipe(map((data: any) => data));
  }
  public getDetailsHistoryFailureEquipment(failure: string, user: string, line: number): Observable<ResponseDataDetailsHistory> {
    return this._httpRequestService.getQuery(`${this._url}/get-details-history-failure-equipment/${failure}/${user}/${line}`).pipe(map((data: any) => data));
  }
  public getAlarmEmissionFromFailures(user: string, line: number): Observable<ResponseDataGetAlarmEmissionFromFailures> {
    return this._httpRequestService.getQuery(`${this._url}/get-alarm-emission-from-failures/${user}/${line}`).pipe(map((data: any) => data));
  }
  public generateSheetFailureXLS(failure: string, user: string, line: number): Observable<ResponseData> {
    return this._httpRequestService.getQuery(`${this._url}/generate-sheet-failure-xls/${failure}/${user}/${line}`).pipe(map((data: any) => data));
  }
  public generateSheetFailurePDF(failure: string, user: string, line: number): Observable<ResponseData> {
    return this._httpRequestService.getQuery(`${this._url}/generate-sheet-failure-pdf/${failure}/${user}/${line}`).pipe(map((data: any) => data));
  }


  public getSymptom(user: string, line: number): Observable<ResponseDataGetSymptomList> {
    return this._httpRequestService.getQuery(`${this._url}/get-symptoms/${user}/${line}`).pipe(map((data: any) => data));
  }
  public getSymptomsActives(user: string, line: number): Observable<ActiveSymptomsListResponse> {
    return this._httpRequestService.getQuery(`${this._url}/get-symptoms-actives/${user}/${line}`).pipe(map((data: any) => data));
  }
  public getSymptomsByEquipment(codeEquipment:string, user: string, line: number): Observable<ResponseDataGetSymptomList> {
    return this._httpRequestService.getQuery(`${this._url}/get-symptoms-by-equipment/${codeEquipment}/${user}/${line}`).pipe(map((data: any) => data));
  }
  public getSymptomById(idSymptom:string, user: string, line: number): Observable<ResponseDataSymptomList> {
    return this._httpRequestService.getQuery(`${this._url}/get-symptom-by-id/${idSymptom}/${user}/${line}`).pipe(map((data: any) => data));
  }
  public registerSymptom(response:RequestDataFormSymptom): Observable<ResponseData> {
    return this._httpRequestService.postQuery(`${this._url}/register-symptom`, response).pipe(map((data:any) => data));
  }
  public updateSymptom(response:RequestDataFormSymptom): Observable<ResponseData> {
    return this._httpRequestService.postQuery(`${this._url}/update-symptom`, response).pipe(map((data:any) => data));
  }
  public deteleSymptom(response:RequestDataDeleteSymtom): Observable<ResponseData> {
    return this._httpRequestService.postQuery(`${this._url}/delete-symptom`, response).pipe(map((data:any) => data));
  }


  public generateMTBF(response: RequestGenerateMTBF): Observable<ResponseDataGenerateMTBF> {
    return this._httpRequestService.postQuery(`${this._url}/generate-mtbf`, response).pipe(map((data:any) => data));
  }
}
