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 { WorkListBodyRequest } from "../models/NotificationBodyReq";
import { EITNotificatonBodyResponse } from "../models/EITNotificationBodyRes";
import { AbsenceNotificatonBodyResponse } from "../models/AbsenceNotificationBodyRes";
import { WorkListButtonRequest } from "../models/NotificationButtonReq";
import { NotificatonButtonResponse } from "../models/NotificationButtonRes";
import { WorklistsubmitterInfoResponse } from "../models/WorklistsubmitterInfoRes";
import { WorkListSubmitterInfoRequest } from "../models/WorklistsubmitterInfoReq";
import { WorkListActionRequest } from "../models/NotificationActionReq";
import { PONotificatonBodyResponse } from "../models/PONotificationBodyRes";
import { MONotificatonBodyResponse } from "../models/MONotificationBodyRes";
import { PRNotificatonBodyResponse } from "../models/PRNotificationBodyRes";
import { StaticInjector } from "@angular/core/src/di/injector";
import { POItemHistoryRes } from "../models/POItemHistoryRes";
import { MOItemHistoryRes } from "../models/MOItemHistoryRes";
import { QuotationAnalysisResponse } from '../models/quotationAnalysisRes';
import { Request } from 'src/app/hmg-common/services/models/request';
import { LoginModel } from '../../authentication/models/LoginModel';

@Injectable()
export class WorklistMainService {
  public static getEITNotificationBody =
    "Services/ERP.svc/REST/GET_EIT_NOTIFICATION_BODY";
  public static getAbsenceNotificationBody =
    "Services/ERP.svc/REST/GET_ABSENCE_NOTIFICATION_BODY";
  public static getPoNotificationBody =
    "Services/ERP.svc/REST/GET_PO_NOTIFICATION_BODY";
  public static getMONotificationBody =
    "Services/ERP.svc/REST/GET_MO_NOTIFICATION_BODY";
  public static getPRNotificationBody =
    "Services/ERP.svc/REST/GET_PR_NOTIFICATION_BODY";
  public static getPOItemHistory = "Services/ERP.svc/REST/GET_PO_ITEM_HISTORY";
  public static getMOItemHistory = "GET_MO_ITEM_HISTORY";
  public static getNotificationButtons =
    "Services/ERP.svc/REST/GET_NOTIFICATION_BUTTONS";
  public static getUserInfo = "Services/ERP.svc/REST/Get_UserInformation";
  public static getNotificationAction =
    "Services/ERP.svc/REST/NOTIFICATION_ACTIONS";
  public static getNotificationRespondAtt =
    "Services/ERP.svc/REST/NOTIFICATION_GET_RESPOND_ATTRIBUTES";
    public static getQutationAnalysisUrl =
    "Services/ERP.svc/REST/GET_QUOTATION_ANALYSIS";
  public static getITGFormTaskCount =
    'http://10.80.100.124:7086/Services/COCWS.svc/REST/ITGGetTaskCountRequestType';
  public static getITGFormTaskDetails =
    'http://10.80.100.124:7086/Services/COCWS.svc/REST/ITGFormsPendingTasks';  



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

  public getEITNotificationBody(
    WorkListBodyRequest: any,
    onError?: any,
    errorLabel?: string
  ): Observable<EITNotificatonBodyResponse> {
    const request = WorkListBodyRequest;
    this.authService.authenticateRequest(request);
    return this.api.post(
      WorklistMainService.getEITNotificationBody,
      request,
      onError,
      errorLabel
    );
  }

  public getAbsencesNotificationBody(
    WorkListBodyRequest: any,
    onError?: any,
    errorLabel?: string
  ): Observable<AbsenceNotificatonBodyResponse> {
    const request = WorkListBodyRequest;
    this.authService.authenticateRequest(request);
    return this.api.post(
      WorklistMainService.getAbsenceNotificationBody,
      request,
      onError,
      errorLabel
    );
  }

  public getMONotificationBody(
    WorkListBodyRequest: any,
    onError?: any,
    errorLabel?: string
  ): Observable<MONotificatonBodyResponse> {
    const request = WorkListBodyRequest;
    this.authService.authenticateRequest(request);
    return this.api.post(
      WorklistMainService.getMONotificationBody,
      request,
      onError,
      errorLabel
    );
  }

  public getPRNotificationBody(
    WorkListBodyRequest: any,
    onError?: any,
    errorLabel?: string
  ): Observable<PRNotificatonBodyResponse> {
    const request = WorkListBodyRequest;
    this.authService.authenticateRequest(request);
    return this.api.post(
      WorklistMainService.getPRNotificationBody,
      request,
      onError,
      errorLabel
    );
  }

  public getPONotificationBody(
    WorkListBodyRequest: any,
    onError?: any,
    errorLabel?: string
  ): Observable<PONotificatonBodyResponse> {
    const request = WorkListBodyRequest;
    this.authService.authenticateRequest(request);
    return this.api.post(
      WorklistMainService.getPoNotificationBody,
      request,
      onError,
      errorLabel
    );
  }

  public getPOItemHistory(
    POItemHistoryReq: any,
    onError?: any,
    errorLabel?: string
  ): Observable<POItemHistoryRes> {
    const request = POItemHistoryReq;
     this.authService.authenticateRequest(request);
   // this.authService.setPublicFields(request);

    return this.api.post(
      WorklistMainService.getPOItemHistory,
      request,
      onError,
      errorLabel
    );
  }

  public getMOItemHistory(
    MOItemHistoryReq: any,
    onError?: any,
    errorLabel?: string
  ): Observable<MOItemHistoryRes> {
    const request = MOItemHistoryReq;
    this.authService.authenticateRequest(request);
    return this.api.post(
      WorklistMainService.getMOItemHistory,
      request,
      onError,
      errorLabel
    );
  }

  public getQutationAnalysis(
    qutationAnalysis: any,
    onError?: any,
    errorLabel?: string
  ): Observable<QuotationAnalysisResponse> {
    const request = qutationAnalysis;
    this.authService.authenticateRequest(request);
    return this.api.post(
      WorklistMainService.getQutationAnalysisUrl,
      request,
      onError,
      errorLabel
    );
  }

  public getNotificationButtons(
    WorkListButtonRequest: any,
    onError?: any,
    errorLabel?: string
  ): Observable<NotificatonButtonResponse> {
    const request = WorkListButtonRequest;
    this.authService.authenticateRequest(request);
    return this.api.post(
      WorklistMainService.getNotificationButtons,
      request,
      onError,
      errorLabel
    );
  }

  public getSubmitterInfo(
    worklistsubmitterInfoObj: any,
    onError?: any,
    errorLabel?: string
  ): Observable<WorklistsubmitterInfoResponse> {
    const request = worklistsubmitterInfoObj;
    this.authService.authenticateRequest(request);
    return this.api.post(
      WorklistMainService.getUserInfo,
      request,
      onError,
      errorLabel
    );
  }

  public actionButton(
    WorkListActionRequest: any,
    onError?: any,
    errorLabel?: string
  ): Observable<any> {
    const request = WorkListActionRequest;
    this.authService.authenticateRequest(request);
    return this.api.post(
      WorklistMainService.getNotificationAction,
      request,
      onError,
      errorLabel
    );
  }

  public notificationResponseAttr(
    notifiResAttRequest: any,
    onError?: any,
    errorLabel?: string
  ): Observable<any> {
    const request = notifiResAttRequest;
    this.authService.authenticateRequest(request);
    return this.api.post(
      WorklistMainService.getNotificationRespondAtt,
      request,
      onError,
      errorLabel
    );
  }

  public getITGCount( onError?: any, errorLabel?: string): Observable<any> {
    const request = new Request;
    console.log(request)
    this.authService.authenticateRequest(request);
    return this.api.postToken(
      WorklistMainService.getITGFormTaskCount,
      request,
      onError,
      errorLabel
    );
  }


  public getITGDetails( onError?: any, errorLabel?: string): Observable<any> {
    const request = new Request;
    console.log(request)
    this.authService.authenticateRequest(request);
    return this.api.postToken(
      WorklistMainService.getITGFormTaskDetails,
      request,
      onError,
      errorLabel
    );
  }

}
