import { Injectable } from '@angular/core';
import { HttpRequestService } from '../http-request.service';
import { map } from 'rxjs';

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

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

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

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

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

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

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

  public getSpecialties(idUser: string, line: number) {
    return this._httpRequestService.getQuery(`specialties/consult/${idUser}/${line}`).pipe(
      map((data: any) => data));
  }

  public getSpecialty(code: string, idUser: string, line: number) {
    return this._httpRequestService.getQuery(`specialties/consult/only/${code}/${idUser}/${line}`).pipe(
      map((data: any) => data));
  }

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

  public registerSpecialty(response: FormData) {
    return this._httpRequestService.postQuery(`specialties/register`, response)
      .pipe(map((data: any) => data));
  }

  public updateSpecialty(response: FormData) {
    return this._httpRequestService.postQuery(`specialties/update`, response)
      .pipe(map((data: any) => data));
  }

  public deleteSpecialty(response: FormData) {
    return this._httpRequestService.postQuery(`specialties/delete`, response)
      .pipe(map((data: any) => data));
  }
}
