
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_day_hours_type_details_list_model.dart';
import 'package:mohem_flutter_app/models/get_mobile_login_info_list_model.dart';
import 'package:mohem_flutter_app/models/get_schedule_shifts_details_list_model.dart';
import 'package:mohem_flutter_app/models/get_time_card_summary_list_model.dart';
import 'package:mohem_flutter_app/api/api_client.dart';

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

  MonthlyAttendanceApiClient._internal();

  factory MonthlyAttendanceApiClient() => _instance;

  Future<GetTimeCardSummaryList?> getTimeCardSummary(String month, int year) async {
    String url = "${ApiConsts.erpRest}GET_TIME_CARD_SUMMARY";
    Map<String, dynamic> postParams = {
      "P_MENU_TYPE": "E",
      "P_SELECTED_RESP_ID": -999,
      "SearchMonth": month,
      "SearchYear": year,
    };

    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel? responseData = GenericResponseModel.fromJson(json);
      return (responseData.getTimeCardSummaryList?.length ?? 0) > 0 ? responseData.getTimeCardSummaryList!.first : null;
    }, url, postParams);
  }

  Future<List<GetDayHoursTypeDetailsList>> getDayHoursTypeDetails(String month, int year) async {
    String url = "${ApiConsts.erpRest}GET_DAY_HOURS_TYPE_DETAILS";
    Map<String, dynamic> postParams = {
      "P_MENU_TYPE": "E",
      "P_PAGE_LIMIT": 100,
      "P_PAGE_NUM": 1,
      "P_SELECTED_RESP_ID": -999,
      "SearchMonth": month,
      "SearchYear": year,
    };
    postParams.addAll(AppState().postParamsJson);
    // postParams["DeviceToken"] = deviceToken;
    // postParams["DeviceType"] = deviceType;
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel? responseData = GenericResponseModel.fromJson(json);
      return responseData.getDayHoursTypeDetailsList ?? [];
    }, url, postParams);
  }


  Future<GetScheduleShiftsDetailsList?> getScheduleShiftsDetails(int pRTPID) async {
    String url = "${ApiConsts.erpRest}GET_SCHEDULE_SHIFTS_DETAILS";
    Map<String, dynamic> postParams = {
      "P_PAGE_LIMIT": 10,
      "P_PAGE_NUM": 1,
      "P_RTP_ID": pRTPID,
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel? responseData = GenericResponseModel.fromJson(json);
      return (responseData.getScheduleShiftsDetailsList?.length ?? 0) > 0 ? responseData.getScheduleShiftsDetailsList!.first : null;
    }, url, postParams);
  }

}