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 {ApproversList} from '../models/approvers'


@Injectable()
export class SubmitAbConfirmService {
  public static cancelHRTransaction='Services/ERP.svc/REST/CANCEL_HR_TRANSACTION';
  public static startAbsenceProcess='Services/ERP.svc/REST/START_ABSENCE_APPROVAL_PROCESS';
  public static getApproversList='Services/ERP.svc/REST/GET_APPROVERS_LIST';
  public static updateAttach='Services/ERP.svc/REST/UPDATE_ATTACHMENT';
  public static delteAttach='Services/ERP.svc/REST/DELETE_ATTACHMENT';
    constructor(
      public api: ConnectorService,
      public authService: AuthenticationService) { }
  
    public cancelHRTransaction(transactionID: any, onError?: any, errorLabel?: string): Observable<any> {
      const request = transactionID;
      this.authService.authenticateRequest(request);
      return this.api.post(SubmitAbConfirmService.cancelHRTransaction, request, onError, errorLabel);
    }

    public startAbApprovalProcess(abProcess: any, onError?: any, errorLabel?: string): Observable<any> {
        const request = abProcess;
        this.authService.authenticateRequest(request);
        return this.api.post(SubmitAbConfirmService.startAbsenceProcess, request, onError, errorLabel);
      }

    public getApproversList(abProcess: any, onError?: any, errorLabel?: string): Observable<ApproversList> {
    const request = abProcess;
    request.P_AME_TRANSACTION_TYPE="SSHRMS";
    request.P_PAGE_NUM=1;
    request.P_PAGE_LIMIT=1000;//check later on
    this.authService.authenticateRequest(request);
    return this.api.post(SubmitAbConfirmService.getApproversList, request, onError, errorLabel);
    }

    public updateAttach(updateAttachReq: any, onError?: any, errorLabel?: string): Observable<any> {
    const request = updateAttachReq;
    this.authService.authenticateRequest(request);
    return this.api.post(SubmitAbConfirmService.updateAttach, request, onError, errorLabel);
    }

    public delteAttach(delteAttachReq: any, onError?: any, errorLabel?: string): Observable<any> {
      const request = delteAttachReq;
      this.authService.authenticateRequest(request);
      return this.api.post(SubmitAbConfirmService.delteAttach, request, onError, errorLabel);
      }
}