import { Injectable } from '@angular/core';
import { HttpRequestService } from '../http-request.service';
import { map, Observable } from 'rxjs';
import { RequestDeleteMeasures, RequestFormMeasures, ResponseDataGetCatalogMeasures } from '../../interfaces/failure-analysis/catalog-measures.interface';
import { ResponseData } from '../resources.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, line: number): Observable<ResponseDataGetCatalogMeasures> {
    return this._httpRequestService.getQuery(`${this._url}/get-catalog-measures-actives/${idUser}/${line}`).pipe(map((data:any) => data))
  }

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

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

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