import { Injectable } from '@angular/core';
import { AuthenticationService } from 'src/app/hmg-common/services/authentication/authentication.service';
import { ConnectorService } from 'src/app/hmg-common/services/connector/connector.service';
import { Observable } from 'rxjs';
import { Request } from 'src/app/hmg-common/services/models/request';
import { OrganizationSalariesResponse } from './organization-salaries.response';
import { OpenMissingSwipesResponse } from './open-missing-swipes.response';
import { PerformanceAppraisalResponse } from './performance-appraisal.response';
import {AttendanceTrackingResponse} from './attendance-tracking.response'

import {OpenPeriodDatesResponse} from '../../services/dashbored/models/openPeriodDatesResponse'
import {GetSubordinatesLeavesRequest} from './models/GetSubordinatesLeavesRequest';
import {GetSubordinatesLeavesResponse} from './models/GetSubordinatesLeavesResponse';
import {GetSubordinatesAttdStatusRequest} from './models/GetSubordinatesAttdStatusRequest';
import {GetSubordinatesAttdStatusResponse} from './models/GetSubordinatesAttdStatusResponse';
import {GetOpenNotificationsResponse} from './models/GetOpenNotificationsResponse'

@Injectable({
  providedIn: 'root'
})
export class DashboredService {
  public static organizationSalariesUrl = 'Services/ERP.svc/REST/GET_ORGANIZATIONS_SALARIES';
  public static openMissingSwipesUrl = 'Services/ERP.svc/REST/GET_OPEN_MISSING_SWIPES';
  public static performanceappraisalUrl = 'Services/ERP.svc/REST/GET_Performance_Appraisal';
  public static attendancetrackingUrl = 'Services/ERP.svc/REST/GET_Attendance_Tracking';

  public static getOpenPeriodDates = 'Services/ERP.svc/REST/GET_OPEN_PERIOD_DATES';
  public static getOpenNotifications = 'Services/ERP.svc/REST/GET_OPEN_NOTIFICATIONS';
  public static getSubordinatesLeaves = 'Services/ERP.svc/REST/GET_SUBORDINATES_LEAVES';
  public static getSubordinatesAttStatus = 'Services/ERP.svc/REST/GET_SUBORDINATES_ATTD_STATUS';

  constructor(
    public con: ConnectorService,
    public authService: AuthenticationService,
  ) { }

  public getOrganizationSalaries(onError ?: any , oerrorLable ?: any): Observable<OrganizationSalariesResponse>{
    const request = new Request();
    this.authService.authenticateRequest(request);
    return this.con.post(
      DashboredService.organizationSalariesUrl,
      request,
      onError,
      oerrorLable
    );
  }

    public getOpenMissingSwipes(onError ?: any, oerrorLable ?: any, isPostNoLoad = false): Observable<OpenMissingSwipesResponse> {
      const request = new Request();
      this.authService.authenticateRequest(request);
      if (isPostNoLoad) {
        return this.con.postNoLoad(DashboredService.openMissingSwipesUrl, request, onError, oerrorLable);
      } else {
        return this.con.post( DashboredService.openMissingSwipesUrl, request, onError, oerrorLable);
      }
  }

  public getPerformanceAppraisal(onError ?: any , oerrorLable ?: any): Observable<PerformanceAppraisalResponse>{
    const request = new Request();
    this.authService.authenticateRequest(request);
    return this.con.post(
      DashboredService.performanceappraisalUrl,
      request,
      onError,
      oerrorLable
    );
}
// tslint:disable-next-line: max-line-length
public getAttendanceTracking(selectedEmployee: any, onError ?: any , oerrorLable ?: any, isPostNoLoad = false): Observable<AttendanceTrackingResponse>{
  const request = selectedEmployee;
  this.authService.authenticateRequest(request);
  if (isPostNoLoad) {
    return this.con.postNoLoad(
      DashboredService.attendancetrackingUrl,
      request,
      onError,
      oerrorLable
    );
  } else {
    return this.con.post(
      DashboredService.attendancetrackingUrl,
      request,
      onError,
      oerrorLable
    );
  }
}
  public getOpenPeriodDates( onError?: any, errorLabel?: string): Observable<OpenPeriodDatesResponse> {
    const request = new Request();
    this.authService.authenticateRequest(request);
    return this.con.post(DashboredService.getOpenPeriodDates, request, onError, errorLabel);
  }
  public getOpenNotifications( onError?: any, errorLabel?: string, isPostNoLoad = false): Observable<GetOpenNotificationsResponse> {
    console.log(isPostNoLoad);
    const request = new Request();
    this.authService.authenticateRequest(request);
    if (isPostNoLoad) {
      return this.con.postNoLoad(DashboredService.getOpenNotifications, request, onError, errorLabel);
    } else {
      return this.con.post(DashboredService.getOpenNotifications, request, onError, errorLabel);
    }
  }
  // tslint:disable-next-line: max-line-length
  public getSubordinatesLeaves( req: GetSubordinatesLeavesRequest, onError?: any, errorLabel?: string): Observable<GetSubordinatesLeavesResponse> {
    this.authService.authenticateRequest(req);
    return this.con.post(DashboredService.getSubordinatesLeaves, req, onError, errorLabel);
  }
  // tslint:disable-next-line: max-line-length
  public getSubordinatesAttStatus( req: GetSubordinatesAttdStatusRequest, onError?: any, errorLabel?: string): Observable<GetSubordinatesAttdStatusResponse> {
    this.authService.authenticateRequest(req);
    return this.con.post(DashboredService.getSubordinatesAttStatus, req, onError, errorLabel);
  }


}
