import { Injectable } from '@angular/core';
import { map, Observable } from 'rxjs';
import { ResponseDataGetCatalogMeasures, RequestFormMeasures, RequestDeleteMeasures } from 'src/app/interfaces/failure-analysis/catalog-measures.interface';
import { ResponseData } from 'src/app/interfaces/response-data';
import { HttpRequestService } from '../resources/http-request.service';

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

  private _url: string;
  constructor( private _httpRequestService: HttpRequestService ) {
    this._url = 'counters-and-triggers';
  }

  public getCatalogMeasures(): Observable<ResponseDataGetCatalogMeasures> {
    return this._httpRequestService.getQuery(`${this._url}/get-catalog-measures`).pipe(map((data:any) => data))
  }
  
  public getCatalogMeasuresActives(idUser: string): Observable<ResponseDataGetCatalogMeasures> {
    return this._httpRequestService.getQueryQA(`${this._url}/get-catalog-measures-actives/${idUser}`).pipe(map((data:any) => data))
  }

  public registerCatalogMeasures(response: RequestFormMeasures): Observable<ResponseData> {
    return this._httpRequestService.postQueryQA(`${this._url}/register-catalog-measures`,response).pipe(map((data:any) => data));
  }

  public updateCatalogMeasures(response: RequestFormMeasures): Observable<ResponseData> {
    return this._httpRequestService.postQueryQA(`${this._url}/update-catalog-measures`,response).pipe(map((data:any) => data));
  }

  public deleteCatalogMeasures(response: RequestDeleteMeasures): Observable<ResponseData> {
    return this._httpRequestService.postQueryQA(`${this._url}/delete-catalog-measures`,response).pipe(map((data:any) => data));
  }

}
