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/get_eit_dff_structure_list_model.dart';
import 'package:mohem_flutter_app/models/my_requests/get_ccp_dff_structure_model.dart';
import 'package:mohem_flutter_app/models/my_requests/get_ccp_output_model.dart';
import 'package:mohem_flutter_app/models/my_requests/get_ccp_transactions_model.dart';
import 'package:mohem_flutter_app/models/my_requests/get_concurrent_programs_model.dart';

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

  MyRequestsApiClient._internal();

  factory MyRequestsApiClient() => _instance;

  Future<List<GetConcurrentProgramsModel>> getConcurrentPrograms() async {
    String url = "${ApiConsts.erpRest}GET_CONCURRENT_PROGRAMS";
    Map<String, dynamic> postParams = {"P_REQUEST_GROUP_ID": 3290};

    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel? responseData = GenericResponseModel.fromJson(json);
      return responseData.getConcurrentProgramsModel ?? [];
    }, url, postParams);
  }

  Future<List<GetCCPTransactionsModel>> getCCPTransactions(String? templateName) async {
    String url = "${ApiConsts.erpRest}GET_CCP_TRANSACTIONS";
    Map<String, dynamic> postParams = {"P_DESC_FLEX_NAME": templateName};

    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel? responseData = GenericResponseModel.fromJson(json);
      return responseData.getCCPTransactionsModel ?? [];
    }, url, postParams);
  }

  Future<GetCCPOutputModel> getCCPOutput(String? requestID) async {
    String url = "${ApiConsts.erpRest}GET_CCP_OUTPUT";
    Map<String, dynamic> postParams = {"P_REQUEST_ID": requestID};

    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel? responseData = GenericResponseModel.fromJson(json);
      return responseData.getCCPOutputModel!;
    }, url, postParams);
  }

  Future<List<GetEITDFFStructureList>> getCCPDFFStructure(String? templateName) async {
    String url = "${ApiConsts.erpRest}GET_CCP_DFF_STRUCTURE";
    Map<String, dynamic> postParams = {"P_DESC_FLEX_NAME": templateName};

    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel? responseData = GenericResponseModel.fromJson(json);
      return responseData.getEITDFFStructureList ?? [];
    }, url, postParams);
  }

}
