import { Injectable } from '@angular/core';
import { map } from 'rxjs';
import { Contract } from 'src/app/interfaces/personal-managment/employee.interface';
import { HttpRequestService } from '../resources/http-request.service';

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

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

  public getConsultOfInterventions(idUser: string) {
    return this._httpRequestService.getQueryQA(`${this._url}/consult/${idUser}`).pipe(
      map((data: any) => data));
  }

  public getDetailsOfInterventionsById(interventionId: number) {
    return this._httpRequestService.getQueryQA(`${this._url}/detail/${interventionId}`).pipe(
      map((data: any) => data));
  }

  public getConsultOfContracts(idUser: string) {
    return this._httpRequestService.getQueryQA(`${this._url}/contract/consult/${idUser}`).pipe(
      map((data: any) => data));
  }

  public getContractById(contractId: string) {
    return this._httpRequestService.getQueryQA(`${this._url}/contract/${contractId}`).pipe(
      map((data: any) => data));
  }

  public storeContract(response: FormData) {
    return this._httpRequestService.postQueryQA(`${this._url}/contract/register`, response)
      .pipe(map((data: any) => data));
  }

  public getAllContracts() {
    return this._httpRequestService.getQueryQA(`${this._url}/contract`).pipe(
      map((data: any) => data));
  }

}
