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

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

  public updateToActiveStatus(response: UpdatedStatusSubcontratist) {
    return this._httpRequestService.postQueryQA(`${this._url}/delete`, response)
      .pipe(map((data: any) => data));
  }

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

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

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

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

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

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

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

  public downloadSubcontratistContractsInfoOnExcel(idSubcontratist: string, idUser: string) {
    return this._httpRequestService.getQueryQA(`${this._url}/download-info-excel/${idSubcontratist}/${idUser}`)
      .pipe(map((data: any) => data));
  }

  public downloadSubcontratistContractsInfoOnPdf(idSubcontratist: string, idUser: string) {
    return this._httpRequestService.getQueryQA(`${this._url}/download-info-pdf/${idSubcontratist}/${idUser}`)
      .pipe(map((data: any) => data));
  }
}
