import { Injectable } from '@angular/core';
import { HttpRequestService } from '../http-request.service';
import { map } from 'rxjs';
import { ActivityEmployee, DeleteFormActivity, DownoloadEmployeeInfo } from '../../interfaces/personal-managment/employee.interface';

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

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

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

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

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

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

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

  public getInterventionsByEmployee(employeeId: string, idUser: string, line: number) {
    return this._httpRequestService.getQuery(`${this._url}/orders/${employeeId}/${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 storeEmployee(response: any) {
    return this._httpRequestService.postQuery(`${this._url}/register`, response)
      .pipe(map((data: any) => data));
  }

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

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

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

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

  public getDetailsOfContractsByEmployee(employeeId: string, idUser: string, line: number) {
    return this._httpRequestService.getQuery(`${this._url}/contracts/history/${employeeId}/${idUser}/${line}`).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));
  }

  public getScheduleActivitiesByEmployee(idEmployee:string, user: string, line: number) {
    return this._httpRequestService.getQuery(`${this._url}/get-schedule-activities-by-employee/${idEmployee}/${user}/${line}`).pipe(map((data:any) => data))
  }
  public registerActivity(requestDataForm: ActivityEmployee){
    return this._httpRequestService.postQuery(`${this._url}/register-activity`, requestDataForm).pipe(map((data:any) => data))
  }  
  public updateActivity(requestDataForm: ActivityEmployee, idActivity: string){
    return this._httpRequestService.postQuery(`${this._url}/update-activity/${idActivity}`, requestDataForm).pipe(map((data:any) => data))
  }
  public deleteActivity(requestDataForm: DeleteFormActivity, idActivity: string){
    return this._httpRequestService.postQuery(`${this._url}/delete-activity/${idActivity}`, requestDataForm).pipe(map((data:any) => data))
  }
  public getScheduleActivitiesByActivity(idActivity: string, user: string, line: number) {
    return this._httpRequestService.getQuery(`${this._url}/get-schedule-activities-by-activity/${idActivity}/${user}/${line}`).pipe(map((data:any) => data))
  }
}
