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() {
    return this._httpRequestService.getQuery(`${this._url}/consult/1`).pipe(
      map((data: any) => data))
  }
  public getAvaibleUsers() {
    return this._httpRequestService.getQuery(`${this._url}/user-avaible/1`).pipe(
      map((data: any) => data))
  }

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

  public getInterventionsByEmployee(employeeId: string) {
    return this._httpRequestService.getQuery(`${this._url}/orders/${employeeId}/1`).pipe(
      map((data: any) => data))
  }

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

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

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

  public getEmployeeById(employeeId: string) {
    return this._httpRequestService.getQuery(`${this._url}/${employeeId}/1`).pipe(
      map((data: any) => data))
  }

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

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

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

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

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