import 'dart:async';

import 'package:mohem_flutter_app/api/api_client.dart';
import 'package:mohem_flutter_app/app_state/app_state.dart';
import 'package:mohem_flutter_app/classes/consts.dart';
import 'package:mohem_flutter_app/models/dashboard/itg_forms_model.dart';
import 'package:mohem_flutter_app/models/generic_response_model.dart';
import 'package:mohem_flutter_app/models/get_absence_collection_notification_body_list_model.dart';
import 'package:mohem_flutter_app/models/get_action_history_list_model.dart';
import 'package:mohem_flutter_app/models/get_attachement_list_model.dart';
import 'package:mohem_flutter_app/models/get_item_creation_ntf_body_list_model.dart';
import 'package:mohem_flutter_app/models/get_mo_Item_history_list_model.dart';
import 'package:mohem_flutter_app/models/get_mo_notification_body_list_model.dart';
import 'package:mohem_flutter_app/models/get_notification_buttons_list_model.dart';
import 'package:mohem_flutter_app/models/get_po_Item_history_list_model.dart';
import 'package:mohem_flutter_app/models/get_po_notification_body_list_model.dart';
import 'package:mohem_flutter_app/models/get_pr_notification_body_list_model.dart';
import 'package:mohem_flutter_app/models/get_quotation_analysis_list_model.dart';
import 'package:mohem_flutter_app/models/get_stamp_ms_notification_body_list_model.dart';
import 'package:mohem_flutter_app/models/get_stamp_ns_notification_body_list_model.dart';
import 'package:mohem_flutter_app/models/get_user_item_type_list.dart';
import 'package:mohem_flutter_app/models/itg_forms_models/itg_request_model.dart';
import 'package:mohem_flutter_app/models/member_information_list_model.dart';
import 'package:mohem_flutter_app/models/notification_get_respond_attributes_list_model.dart';
import 'package:mohem_flutter_app/models/update_user_item_type_list.dart';
import 'package:mohem_flutter_app/models/worklist/GetRFCEmployeeList.dart';
import 'package:mohem_flutter_app/models/worklist/get_favorite_replacements_model.dart';
import 'package:mohem_flutter_app/models/worklist/hr/eit_otification_body_model.dart';
import 'package:mohem_flutter_app/models/worklist/hr/get_basic_det_ntf_body_list_model.dart';
import 'package:mohem_flutter_app/models/worklist/hr/get_contact_notification_body_list_model.dart';
import 'package:mohem_flutter_app/models/worklist/hr/get_phones_notification_body_list_model.dart';
import 'package:mohem_flutter_app/models/worklist/replacement_list_model.dart';
import 'package:mohem_flutter_app/models/worklist_response_model.dart';

class WorkListApiClient {
  static final WorkListApiClient _instance = WorkListApiClient._internal();

  WorkListApiClient._internal();

  factory WorkListApiClient() => _instance;

  Future<List<WorkListResponseModel>?> getWorkList(int pPageNum, String pItemType, String pNotificationType,
      {String pSearchUser = "", String pSearchItemType = "", String pSentDate = "", String pSearchSubject = ""}) async {
    String url = "${ApiConsts.erpRest}GET_WORKLIST";
    Map<String, dynamic> postParams = {
      "P_NOTIFICATION_TYPE": pNotificationType,
      "P_PAGE_NUM": pPageNum,
      "P_PAGE_LIMIT": 25,
      "P_ITEM_TYPE": pItemType,
      "P_SEARCH_FROM_USER": pSearchUser,
      "P_SEARCH_ITEM_TYPE_DSP_NAME": pSearchItemType,
      "P_SEARCH_SENT_DATE": pSentDate,
      "P_SEARCH_SUBJECT": pSearchSubject
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel? responseData = GenericResponseModel.fromJson(json);
      return responseData.getWorkList;
    }, url, postParams);
  }

  Future<ItgFormsModel?> getITGTaskCountRequestType() async {
    String url = "${ApiConsts.cocRest}ITGGetTaskCountRequestType";
    Map<String, dynamic> postParams = {};
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      ItgFormsModel responseData = ItgFormsModel.fromJson(json);
      return responseData;
    }, url, postParams);
  }

  Future<GenericResponseModel> getSubordinatesLeaves(String fromDate, String toDate) async {
    String url = "${ApiConsts.erpRest}GET_SUBORDINATES_LEAVES";
    Map<String, dynamic> postParams = {"P_DATE_FROM": "/Date(1639861200000+0300)/", "P_DATE_TO": "/Date(1640120400000+0300)/"};
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData;
    }, url, postParams);
  }

  Future<List<GetAttachementList>> getAttachments(int pNotificationID) async {
    String url = "${ApiConsts.erpRest}GET_ATTACHMENTS";
    Map<String, dynamic> postParams = {"P_NOTIFICATION_ID": pNotificationID};
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData.getAttachementList ?? [];
    }, url, postParams);
  }

  Future<List<GetRFCEmployeeList>> getRFCEmployeeeList(int pNotificationID) async {
    String url = "${ApiConsts.erpRest}GET_RFC_EMPLOYEE_LIST";
    Map<String, dynamic> postParams = {"P_NOTIFICATION_ID": pNotificationID, "P_PAGE_NUM": 1, "P_PAGE_LIMIT": 10};
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData.getRFCEmployeeListList ?? [];
    }, url, postParams);
  }

  Future<List<GetActionHistoryList>> getActionHistory(int pNotificationID) async {
    String url = "${ApiConsts.erpRest}GET_ACTION_HISTORY";
    Map<String, dynamic> postParams = {
      "P_NOTIFICATION_ID": pNotificationID,
      "P_PAGE_LIMIT": 100,
      "P_PAGE_NUM": 1,
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData.getActionHistoryList ?? [];
    }, url, postParams);
  }

  Future<List<GetNotificationButtonsList>> getNotificationButtons(int pNotificationID) async {
    String url = "${ApiConsts.erpRest}GET_NOTIFICATION_BUTTONS";
    Map<String, dynamic> postParams = {"P_NOTIFICATION_ID": pNotificationID};
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData.getNotificationButtonsList ?? [];
    }, url, postParams);
  }

  Future<List<NotificationGetRespondAttributesList>> notificationGetRespondAttributes(int pNotificationID) async {
    String url = "${ApiConsts.erpRest}NOTIFICATION_GET_RESPOND_ATTRIBUTES";
    Map<String, dynamic> postParams = {"P_NOTIFICATION_ID": pNotificationID};
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData.notificationGetRespondAttributesList ?? [];
    }, url, postParams);
  }

  Future<GenericResponseModel> getBasicDetNTFBody(int pNotificationID, int pTransactionID) async {
    String url = "${ApiConsts.erpRest}GET_BASIC_DET_NTF_BODY";
    Map<String, dynamic> postParams = {
      "P_NOTIFICATION_ID": pNotificationID,
      "P_TRANSACTION_ID": pTransactionID,
      "P_PAGE_LIMIT": 100,
      "P_PAGE_NUM": 1,
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData;
    }, url, postParams);
  }

  Future<MemberInformationListModel> getUserInformation(int pSelectedResopID, String selectedEmployeeNumber) async {
    String url = "${ApiConsts.erpRest}Get_UserInformation";
    Map<String, dynamic> postParams = {
      "P_SELECTED_RESP_ID": pSelectedResopID,
      "P_PAGE_LIMIT": 100,
      "P_PAGE_NUM": 1,
    };
    postParams.addAll(AppState().postParamsJson);
    postParams["P_SELECTED_EMPLOYEE_NUMBER"] = selectedEmployeeNumber;
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData.memberInformationList![0];
    }, url, postParams);
  }

  Future<List<GetStampMsNotificationBodyList>> getStampMsNotificationBody(int pNotificationID, int pTransactionID) async {
    String url = "${ApiConsts.erpRest}GET_STAMP_MS_NOTIFICATION_BODY";
    Map<String, dynamic> postParams = {
      "P_NOTIFICATION_ID": pNotificationID,
      "P_TRANSACTION_ID": pTransactionID,
      "P_PAGE_LIMIT": 100,
      "P_PAGE_NUM": 1,
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData.getStampMsNotificationBodyList ?? [];
    }, url, postParams);
  }

  Future<List<GetStampNsNotificationBodyList>> getStampNsNotificationBody(int pNotificationID, int pTransactionID) async {
    String url = "${ApiConsts.erpRest}GET_STAMP_NS_NOTIFICATION_BODY";
    Map<String, dynamic> postParams = {
      "P_NOTIFICATION_ID": pNotificationID,
      "P_TRANSACTION_ID": pTransactionID,
      "P_PAGE_LIMIT": 100,
      "P_PAGE_NUM": 1,
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData.getStampNsNotificationBodyList ?? [];
    }, url, postParams);
  }

  // Future<List<GetAbsenceCollectionNotificationBodyList>> getAbsenceNotificationBody(int pNotificationID, int pTransactionID) async {
  //   String url = "${ApiConsts.erpRest}GET_ABSENCE_NOTIFICATION_BODY";
  //   Map<String, dynamic> postParams = {
  //     "P_NOTIFICATION_ID": pNotificationID,
  //     "P_TRANSACTION_ID": pTransactionID,
  //     "P_PAGE_LIMIT": 100,
  //     "P_PAGE_NUM": 1,
  //   };
  //   postParams.addAll(AppState().postParamsJson);
  //   return await ApiClient().postJsonForObject((json) {
  //     GenericResponseModel responseData = GenericResponseModel.fromJson(json);
  //     return responseData.getAbsenceCollectionNotificationBodyList ?? [];
  //   }, url, postParams);
  // }

  Future<GenericResponseModel> postNotificationActions(Map<String, dynamic> postParams) async {
    String url = "${ApiConsts.erpRest}NOTIFICATION_ACTIONS";
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData;
    }, url, postParams);
  }

  Future<List<GetMoNotificationBodyList>> getMoNotificationBody(int pNotificationID, int pTransactionID) async {
    String url = "${ApiConsts.erpRest}GET_MO_NOTIFICATION_BODY";
    Map<String, dynamic> postParams = {
      "P_NOTIFICATION_ID": pNotificationID,
      "P_TRANSACTION_ID": pTransactionID,
      "P_PAGE_LIMIT": 100,
      "P_PAGE_NUM": 1,
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData.getMoNotificationBodyList ?? [];
    }, url, postParams);
  }

  Future<GetPoNotificationBodyList?> getPoNotificationBody(int pNotificationID, int pTransactionID) async {
    String url = "${ApiConsts.erpRest}GET_PO_NOTIFICATION_BODY";
    Map<String, dynamic> postParams = {
      "P_NOTIFICATION_ID": pNotificationID,
      "P_TRANSACTION_ID": pTransactionID,
      "P_PAGE_LIMIT": 100,
      "P_PAGE_NUM": 1,
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData.getPoNotificationBodyList;
    }, url, postParams);
  }

  Future<GetPrNotificationBodyList?> getPRNotificationBody(int pNotificationID, int pTransactionID) async {
    String url = "${ApiConsts.erpRest}GET_PR_NOTIFICATION_BODY";
    Map<String, dynamic> postParams = {
      "P_NOTIFICATION_ID": pNotificationID,
      "P_TRANSACTION_ID": pTransactionID,
      "P_PAGE_LIMIT": 100,
      "P_PAGE_NUM": 1,
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData.getPrNotificationBodyList;
    }, url, postParams);
  }

  Future<List<GetMoItemHistoryList>> getMoItemHistory(int pItemID, int pOrgID) async {
    String url = "${ApiConsts.erpRest}GET_MO_ITEM_HISTORY";
    Map<String, dynamic> postParams = {
      "P_ITEM_ID": pItemID,
      "P_PAGE_LIMIT": 100,
      "P_PAGE_NUM": 1,
      "P_ORG_ID": pOrgID,
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData.getMoItemHistoryList ?? [];
    }, url, postParams);
  }

  Future<List<GetPoItemHistoryList>> getPoItemHistory(int pItemID) async {
    String url = "${ApiConsts.erpRest}GET_PO_ITEM_HISTORY";
    Map<String, dynamic> postParams = {
      "P_ITEM_ID": pItemID,
      "P_PAGE_LIMIT": 100,
      "P_PAGE_NUM": 1,
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData.getPoItemHistoryList ?? [];
    }, url, postParams);
  }

  Future<List<GetQuotationAnalysisList>> getQuotationAnalysis(int pItemID, int pPoHeaderId) async {
    String url = "${ApiConsts.erpRest}GET_QUOTATION_ANALYSIS";
    Map<String, dynamic> postParams = {
      "P_ITEM_ID": pItemID,
      "P_PAGE_LIMIT": 100,
      "P_PAGE_NUM": 1,
      "P_PO_HEADER_ID": pPoHeaderId,
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData.getQuotationAnalysisList ?? [];
    }, url, postParams);
  }

  Future<GetItemCreationNtfBodyList?> getItemCreationNtfBody(int pNotificationID, int pTransactionID) async {
    String url = "${ApiConsts.erpRest}GET_ITEM_CREATION_NTF_BODY";
    Map<String, dynamic> postParams = {
      "P_NOTIFICATION_ID": pNotificationID,
      "P_TRANSACTION_ID": pTransactionID,
      "P_PAGE_LIMIT": 100,
      "P_PAGE_NUM": 1,
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData.getItemCreationNtfBodyList;
    }, url, postParams);
  }

  Future<ITGRequest?> getITGFormDetails(String requestType, int taskId, int itemId, String employeeNumber) async {
    String url = "${ApiConsts.cocRest}ITGGetFormDetials";
    Map<String, dynamic> postParams = {
      "RequestType": requestType,
      "TaskID": taskId,
      "ItemID": itemId,
      "EmployeeNumber": employeeNumber,
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      ItgFormsModel responseData = ItgFormsModel.fromJson(json);
      return responseData.itgRequest;
    }, url, postParams);
  }

  Future<ITGRequest?> rejectITGRequest(String requestType, int taskId, int itemId, String employeeNumber, String comments) async {
    String url = "${ApiConsts.cocRest}ITGRejectRequest";
    Map<String, dynamic> postParams = {
      "RequestType": requestType,
      "TaskID": taskId,
      "ItemID": itemId,
      "EmployeeNumber": employeeNumber,
      "Comments": comments,
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      ItgFormsModel responseData = ItgFormsModel.fromJson(json);
      return responseData.itgRequest;
    }, url, postParams);
  }

  Future<ITGRequest?> approveITGRequest(String requestType, int taskId, int itemId, String employeeNumber, String comments) async {
    String url = "${ApiConsts.cocRest}ITGApproveRequest";
    Map<String, dynamic> postParams = {
      "RequestType": requestType,
      "TaskID": taskId,
      "ItemID": itemId,
      "EmployeeNumber": employeeNumber,
      "Comments": comments,
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      ItgFormsModel responseData = ItgFormsModel.fromJson(json);
      return responseData.itgRequest;
    }, url, postParams);
  }

  Future<ITGRequest?> delegateITGRequest(String requestType, int taskId, int itemId, String employeeNumber, String newUserEMPId, String comments) async {
    String url = "${ApiConsts.cocRest}ITGDelegateRequest";
    Map<String, dynamic> postParams = {
      "RequestType": requestType,
      "TaskID": taskId,
      "ItemID": itemId,
      "EmployeeNumber": employeeNumber,
      "NewUserEMPId": newUserEMPId,
      "Comments": comments,
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      ItgFormsModel responseData = ItgFormsModel.fromJson(json);
      return responseData.itgRequest;
    }, url, postParams);
  }

  // ANSWER = 'Services/COCWS.svc/REST/ITGAnswer';

  Future<ITGRequest?> answerITGRequest(String requestType, int taskId, int itemId, String employeeNumber, String newUserEMPId, String comments) async {
    String url = "${ApiConsts.cocRest}ITGAnswer";
    Map<String, dynamic> postParams = {
      "RequestType": requestType,
      "TaskID": taskId,
      "ItemID": itemId,
      "EmployeeNumber": employeeNumber,
      "Comments": comments,
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      ItgFormsModel responseData = ItgFormsModel.fromJson(json);
      return responseData.itgRequest;
    }, url, postParams);
  }

  Future<ITGRequest?> informationITGRequest(String requestType, int taskId, int itemId, String employeeNumber, String newUserEMPId, String comments) async {
    String url = "${ApiConsts.cocRest}ITGRequestInformation";
    Map<String, dynamic> postParams = {
      "RequestType": requestType,
      "TaskID": taskId,
      "ItemID": itemId,
      "EmployeeNumber": employeeNumber,
      "NewUserEMPId": newUserEMPId,
      "Comments": comments,
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      ItgFormsModel responseData = ItgFormsModel.fromJson(json);
      return responseData.itgRequest;
    }, url, postParams);
  }

  //HR Detail Screen Requests
  Future<List<GetEitCollectionNotificationBodyList>?> GetEitNotificationBody(int? notificationId) async {
    String url = "${ApiConsts.erpRest}GET_EIT_NOTIFICATION_BODY";
    Map<String, dynamic> postParams = {
      "P_NOTIFICATION_ID": notificationId,
      "P_PAGE_LIMIT": 100,
      "P_PAGE_NUM": 1,
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData.getEITCollectionNotificationBodyList;
    }, url, postParams);
  }

  Future<List<GetPhonesNotificationBodyList>?> getPhonesNotificationBodyList(int? notificationId) async {
    String url = "${ApiConsts.erpRest}GET_PHONES_NOTIFICATION_BODY";
    Map<String, dynamic> postParams = {
      "P_NOTIFICATION_ID": notificationId,
      "P_PAGE_LIMIT": 100,
      "P_PAGE_NUM": 1,
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData.getPhonesNotificationBodyList;
    }, url, postParams);
  }

  Future<List<GetBasicDetNtfBodyList>?> getBasicDetNtfBodyList(int? notificationId) async {
    String url = "${ApiConsts.erpRest}GET_BASIC_DET_NTF_BODY";
    Map<String, dynamic> postParams = {
      "P_NOTIFICATION_ID": notificationId,
      "P_PAGE_LIMIT": 100,
      "P_PAGE_NUM": 1,
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData.getBasicDetNtfBodyList;
    }, url, postParams);
  }

  Future<List<GetAbsenceCollectionNotificationBodyList>?> getAbsenceNotificationBody(int? notificationId) async {
    String url = "${ApiConsts.erpRest}GET_ABSENCE_NOTIFICATION_BODY";
    Map<String, dynamic> postParams = {
      "P_NOTIFICATION_ID": notificationId,
      "P_PAGE_LIMIT": 100,
      "P_PAGE_NUM": 1,
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData.getAbsenceCollectionNotificationBodyList;
    }, url, postParams);
  }

  Future<GetContactNotificationBodyList?> getContactNotificationBodyList(int? notificationId) async {
    String url = "${ApiConsts.erpRest}GET_CONTACT_NOTIFICATION_BODY";
    Map<String, dynamic> postParams = {
      "P_NOTIFICATION_ID": notificationId,
      "P_PAGE_LIMIT": 100,
      "P_PAGE_NUM": 1,
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData.getContactNotificationBodyList;
    }, url, postParams);
  }

  Future<List<GetFavoriteReplacements>?> getFavoriteReplacementWithoutImage() async {
    String url = "${ApiConsts.erpRest}Mohemm_GetFavoriteReplacementsWithoutImage";
    Map<String, dynamic> postParams = {};
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData.mohemmGetFavoriteReplacementsList;
    }, url, postParams);
  }

  Future<List<GetFavoriteReplacements>?> getFavoriteReplacementWithImage(String selectedFavLetter) async {
    String url = "${ApiConsts.erpRest}Mohemm_GetFavoriteReplacements";
    Map<String, dynamic> postParams = {"ItgFilter": selectedFavLetter};
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData.mohemmGetFavoriteReplacementsList;
    }, url, postParams);
  }

  Future<List<GetFavoriteReplacements>?> getFavoriteReplacementWithImageNew(String selectedFavLetter) async {
    String url = "${ApiConsts.erpRest}Mohemm_GetFavoriteReplacements_Images";
    Map<String, dynamic> postParams = {"ItgFilter": selectedFavLetter};
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData.mohemmGetFavoriteReplacementsList;
    }, url, postParams);
  }

  Future<GenericResponseModel> changeFavoriteReplacements({required String email, required String employeName, required String image, required String userName, bool isFav = false}) async {
    String url = "${ApiConsts.erpRest}Mohemm_ChangeFavoriteReplacements";
    Map<String, dynamic> postParamsObj = {
      "EMAIL_ADDRESS": email,
      "EMPLOYEE_DISPLAY_NAME": employeName,
      "EMPLOYEE_IMAGE": image,
      "IsFavorite": isFav,
      "USER_NAME": userName,
    };
    Map<String, dynamic> postParams = {
      "Mohemm_ChangeReplacementsInputList": [postParamsObj],
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData;
    }, url, postParams);
  }

  Future<List<ReplacementList>?> searchUserByInput({String userId = "", String userName = "", String email = ""}) async {
    String url = "${ApiConsts.erpRest}GET_REPLACEMENT_LIST";
    Map<String, dynamic> postParams = {
      "P_SEARCH_USER_NAME": userId,
      "P_SEARCH_EMPLOYEE_DISPLAY_NAME": userName,
      "P_SEARCH_EMAIL_ADDRESS": email,
      "P_PAGE_LIMIT": 50,
      "P_PAGE_NUM": 1,
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData.replacementList;
    }, url, postParams);
  }

  Future<GenericResponseModel> submitComment({String? comment, String? email, String? userId, int? notificationId, required String apiMode, int? approverIndex = null}) async {
    String url = "${ApiConsts.erpRest}NOTIFICATION_ACTIONS";
    Map<String, dynamic> postParams = {
      "P_COMMENTS": comment,
      "P_ACTION_MODE": apiMode,
      "P_EMAIL_ADDRESS": email,
      "P_FORWARD_TO_USER_NAME": userId,
      "P_NOTIFICATION_ID": notificationId,
      "P_APPROVER_INDEX": approverIndex,
      "RespondAttributeList": []
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData;
    }, url, postParams);
  }

  Future<List<GetUserItemTypesList>> getUserItemTypes() async {
    String url = "${ApiConsts.erpRest}GET_USER_ITEM_TYPES";
    Map<String, dynamic> postParams = {};
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData.getUserItemTypesList ?? [];
    }, url, postParams);
  }

  Future<UpdateUserItemTypesList?> updateUserItemTypes(List<Map<String, dynamic>> itemList) async {
    String url = "${ApiConsts.erpRest}UPDATE_USER_ITEM_TYPES";
    Map<String, dynamic> postParams = {"UpdateItemTypeList": itemList};
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData.updateUserItemTypesList;
    }, url, postParams);
  }
}
