import { Injectable } from '@angular/core';
import { map } from 'rxjs';
import { DownoloadEmployeeInfo, Employee, UpdatedStatusEmployee } from 'src/app/interfaces/personal-managment/employee.interface';
import { HttpRequestService } from '../resources/http-request.service';

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

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

  public getConsultOfEmployees(idUser: string) {
    return this._httpRequestService.getQueryQA(`${this._url}/consult/${idUser}`).pipe(
      map((data: any) => data))
  }

  public getAvaibleUsers(employeeId: string) {
    return this._httpRequestService.getQueryQA(`${this._url}/user-avaible/${employeeId}`).pipe(
      map((data: any) => data))
  }

  public getDocumentsByEmployee(employeeId: string) {
    return this._httpRequestService.getQueryQA(`${this._url}/documents/${employeeId}`).pipe(
      map((data: any) => data))
  }

    public getLastDocumentsByEmployee(employeeId: string) {
    return this._httpRequestService.getQueryQA(`${this._url}/last-documents/${employeeId}`).pipe(
      map((data: any) => data))
  }

  public getInterventionsByEmployee(employeeId: string, idUser: string) {
    return this._httpRequestService.getQueryQA(`${this._url}/orders/${employeeId}/${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: UpdatedStatusEmployee) {
    return this._httpRequestService.putQueryQA(`${this._url}/active-employee/${response.EMPLOYEE_ID}`, response)
      .pipe(map((data: any) => data));
  }

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

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

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

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

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

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

public DownoloadEmployeeInfoOnExcel(response: DownoloadEmployeeInfo){
  return this._httpRequestService.postQueryQA(`${this._url}/downoload-details-excel`, response)
  .pipe(map((data: any) => data));
}

public DownoloadEmployeeInfoOnPdf(response: DownoloadEmployeeInfo){
  return this._httpRequestService.postQueryQA(`${this._url}/downoload-details-pdf`, response)
  .pipe(map((data: any) => data));
}

}
