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

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

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

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

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

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

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

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

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

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

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

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

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

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

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