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() {
    return this._httpRequestService.getQuery(`${this._url}/consult/1`).pipe(
      map((data: any) => data));
  }

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

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

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

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

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

}
