import { Injectable } from '@angular/core';
import { map } from 'rxjs';
import { DownoloadSubcontratistInfo, Subcontratist, UpdatedStatusSubcontratist } from 'src/app/interfaces/personal-managment/subcontractist.interface';
import { HttpRequestService } from '../resources/http-request.service';

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

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

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

  public updateToInactiveStatus(response: UpdatedStatusSubcontratist) {
    return this._httpRequestService.putQuery(`${this._url}/inactive-subcontratist/${response.ID_SUBCONTRATIST}`, response)
      .pipe(map((data: any) => data));
  }

  public storeSubcontratist(response: Subcontratist) {
    return this._httpRequestService.postQuery(`${this._url}`, response)
      .pipe(map((data: any) => data));
  }

  public getSubcontratistById(subcontratistId: string) {
    return this._httpRequestService.getQuery(`${this._url}/subcontratist/${subcontratistId}/1`).pipe(
      map((data: any) => data));
  }

  public updateSubcontratist(response: Subcontratist, idSubcontratist: string) {
    return this._httpRequestService.putQuery(`${this._url}/${idSubcontratist}`, response)
      .pipe(map((data: any) => data));
  }

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

  public getActiveSubcontratists() {
    return this._httpRequestService.getQuery(`${this._url}/active-subcontratists/1`).pipe(
      map((data: any) => data));
  }

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

  public getContractsBySubcontratist(subcontratistId: string) {
    return this._httpRequestService.getQuery(`${this._url}/contracts/history/${subcontratistId}/1`).pipe(
      map((data: any) => data));
  }

  public downoloadSubcontratistContractsInfoOnExcel(response: any) {
    return this._httpRequestService.postQuery(`${this._url}/downoload-info-excel`, response)
      .pipe(map((data: any) => data));
  }
  
  public downoloadSubcontratistContractsInfoOnPdf(response: DownoloadSubcontratistInfo) {
    return this._httpRequestService.postQuery(`${this._url}/downoload-info-pdf`, response)
      .pipe(map((data: any) => data));
  }
}
