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/basic_member_information_model.dart';
import 'package:mohem_flutter_app/models/check_mobile_app_version_model.dart';
import 'package:mohem_flutter_app/models/dashboard/get_attendance_tracking_list_model.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/member_login_list_model.dart';
import 'package:uuid/uuid.dart';

import 'api_client.dart';

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

  DashboardApiClient._internal();

  factory DashboardApiClient() => _instance;

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

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

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

  Future<GenericResponseModel?> getAccrualBalances() async {
    String url = "${ApiConsts.erpRest}GET_ACCRUAL_BALANCES";
    Map<String, dynamic> postParams = {"P_EFFECTIVE_DATE": "1/30/2022"};
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData;
    }, url, postParams);
  }

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

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

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

  //Mark Attendance
  Future<GenericResponseModel?> markAttendance({String lat = "0", String? long = "0", required int pointType, String nfcValue = "", bool isGpsRequired = false}) async {
    String url = "${ApiConsts.swpRest}AuthenticateAndSwipeUserSupportNFC";
    var uuid = Uuid();
    // Generate a v4 (random) id

    Map<String, dynamic> postParams = {
      "UID": uuid.v4(), //Mobile Id
      "Latitude": lat,
      "Longitude": long,
      "QRValue": "",
      "PointType": pointType, // NFC=2, Wifi = 3, QR= 1,
      "NFCValue": nfcValue,
      "WifiValue": "",
      "IsGpsRequired": isGpsRequired
    };
    postParams.addAll(AppState().postParamsJson);
    return await ApiClient().postJsonForObject((json) {
      GenericResponseModel responseData = GenericResponseModel.fromJson(json);
      return responseData;
    }, url, postParams);
  }
}
