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/generic_response_model.dart';
import 'package:mohem_flutter_app/models/monthly_pay_slip/get_deductions_List_model.dart';
import 'package:mohem_flutter_app/models/monthly_pay_slip/get_earnings_list_model.dart';
import 'package:mohem_flutter_app/models/monthly_pay_slip/get_pay_slip_list_model.dart';
import 'package:mohem_flutter_app/models/monthly_pay_slip/get_payment_information_list_model.dart';
import 'package:mohem_flutter_app/models/monthly_pay_slip/get_summary_of_payment_list_model.dart';

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

  MonthlyPaySlipApiClient._internal();

  factory MonthlyPaySlipApiClient() => _instance;

  Future<List<GetPayslipList>> getPaySlip() async {
    String url = "${ApiConsts.erpRest}GET_PAYSLIP";
    Map<String, dynamic> postParams = {"P_MENU_TYPE": "E", "P_SELECTED_RESP_ID": -999};
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel? responseData = GenericResponseModel.fromJson(json);
      return responseData.getPayslipList ?? [];
    }, url, postParams);
  }

  Future<List<GetSummaryOfPaymentList>> getSummaryOfPayment(int pActionContextID) async {
    String url = "${ApiConsts.erpRest}GET_SUMMARY_OF_PAYMENT";
    Map<String, dynamic> postParams = {"P_ACTION_CONTEXT_ID": pActionContextID};
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel? responseData = GenericResponseModel.fromJson(json);
      return responseData.getSummaryOfPaymentList ?? [];
    }, url, postParams);
  }

  Future<List<GetPaymentInformationList>> getPaymentInformation(int pActionContextID) async {
    String url = "${ApiConsts.erpRest}GET_PAYMENT_INFORMATION";
    Map<String, dynamic> postParams = {"P_ACTION_CONTEXT_ID": pActionContextID};
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel? responseData = GenericResponseModel.fromJson(json);
      return responseData.getPaymentInformationList ?? [];
    }, url, postParams);
  }

  Future<List<GetDeductionsList>> getDeductions(int pActionContextID) async {
    String url = "${ApiConsts.erpRest}GET_DEDUCTIONS";
    Map<String, dynamic> postParams = {"P_ACTION_CONTEXT_ID": pActionContextID, "P_PAGE_LIMIT": 100, "P_PAGE_NUM": 1};
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel? responseData = GenericResponseModel.fromJson(json);
      return responseData.getDeductionsList ?? [];
    }, url, postParams);
  }

  Future<List<GetEarningsList>> getEarnings(int pActionContextID) async {
    String url = "${ApiConsts.erpRest}GET_EARNINGS";
    Map<String, dynamic> postParams = {"P_ACTION_CONTEXT_ID": pActionContextID, "P_PAGE_LIMIT": 100, "P_PAGE_NUM": 1};
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel? responseData = GenericResponseModel.fromJson(json);
      return responseData.getEarningsList ?? [];
    }, url, postParams);
  }
}
