import 'dart:async';

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/get_eit_dff_structure_list_model.dart';
import 'package:mohem_flutter_app/models/get_eit_transaction_list_model.dart';

import 'api_client.dart';

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

  MyAttendanceApiClient._internal();

  factory MyAttendanceApiClient() => _instance;

  Future<List<GetEITTransactionList>?> getEitTransaction(String pFunctionName) async {
    String url = "${ApiConsts.erpRest}GET_EIT_TRANSACTIONS";
    Map<String, dynamic> postParams = {"P_PAGE_LIMIT": 50, "P_PAGE_NUM": 1, "P_SELECTED_RESP_ID": -999, "P_MENU_TYPE": "E", "P_FUNCTION_NAME": pFunctionName};
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel? responseData = GenericResponseModel.fromJson(json);
      return responseData.getEITTransactionList ?? [];
    }, url, postParams);
  }

  Future<GenericResponseModel> getEitDffStructure(String pFunctionName) async {
    String url = "${ApiConsts.erpRest}GET_EIT_DFF_STRUCTURE";
    Map<String, dynamic> postParams = {"P_SELECTED_RESP_ID": -999, "P_MENU_TYPE": "E", "P_FUNCTION_NAME": pFunctionName};
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel? responseData = GenericResponseModel.fromJson(json);
      return responseData;
    }, url, postParams);
  }

  Future<ESERVICESVS> getValueSetValues(String pSegmentName, String pDescFlexContextCode, String pDescFlexName, List<Map<String, dynamic>> list) async {
    String url = "${ApiConsts.erpRest}GET_VALUE_SET_VALUES";
    Map<String, dynamic> postParams = {
      "P_SELECTED_RESP_ID": -999,
      "P_MENU_TYPE": "E",
      "P_PAGE_LIMIT": 1000,
      "P_PAGE_NUM": 1,
      "P_PARENT_VALUE": null,
      "P_SEGMENT_NAME": pSegmentName,
      "P_DESC_FLEX_CONTEXT_CODE": pDescFlexContextCode,
      "P_DESC_FLEX_NAME": pDescFlexName,
      "GetValueSetValuesTBL": list,
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel? responseData = GenericResponseModel.fromJson(json);
      return responseData.getValueSetValuesList!.first;
    }, url, postParams);
  }
}
