import { Injectable } from '@angular/core';
import { map, Observable } from 'rxjs';
import { ResponseDataDetailsHistory, ResponseDataGetAlarmEmissionFromFailures, ResponseDataGetFailureLog, ResponseDataGetHistoryFailureEquipment } from 'src/app/interfaces/failure-analysis/failure.interface';
import { ResponseData } from 'src/app/interfaces/response-data';
import { HttpRequestService } from '../resources/http-request.service';

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

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

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

  public getHistoryFailureEquipment(codeEquipment: string): Observable<ResponseDataGetHistoryFailureEquipment> {
    return this._httpRequestService.getQuery(`${this._url}/get-history-failure-equipment/${codeEquipment}`).pipe(map((data: any) => data));
  }

  public getDetailsHistoryFailureEquipment(failure: string): Observable<ResponseDataDetailsHistory> {
    return this._httpRequestService.getQuery(`${this._url}/get-details-history-failure-equipment/${failure}`).pipe(map((data: any) => data));
  }

  public getAlarmEmissionFromFailures(): Observable<ResponseDataGetAlarmEmissionFromFailures> {
    return this._httpRequestService.getQuery(`${this._url}/get-alarm-emission-from-failures`).pipe(map((data: any) => data));
  }

  public generateSheetFailureXLS(failure: string): Observable<ResponseData> {
    return this._httpRequestService.getQuery(`${this._url}/generate-sheet-failure-xls/${failure}`).pipe(map((data: any) => data));
  }

  public generateSheetFailurePDF(failure: string): Observable<ResponseData> {
    return this._httpRequestService.getQuery(`${this._url}/generate-sheet-failure-pdf/${failure}`).pipe(map((data: any) => data));
  }
}
