import 'dart:io';

import 'package:hmg_patient_app/config/config.dart';
import 'package:hmg_patient_app/config/shared_pref_kay.dart';
import 'package:hmg_patient_app/core/service/base_service.dart';
import 'package:hmg_patient_app/core/viewModels/project_view_model.dart';
import 'package:hmg_patient_app/models/Appointments/AppoimentAllHistoryResultList.dart';
import 'package:hmg_patient_app/models/Appointments/DoctorProfile.dart';
import 'package:hmg_patient_app/models/Appointments/PatientShareResposne.dart';
import 'package:hmg_patient_app/models/Appointments/doctor_pre_post_image.dart';
import 'package:hmg_patient_app/models/Appointments/laser_body_parts.dart';
import 'package:hmg_patient_app/models/Authentication/authenticated_user.dart';
import 'package:hmg_patient_app/models/Request.dart';
import 'package:hmg_patient_app/models/apple_pay_request.dart';
import 'package:hmg_patient_app/services/authentication/auth_provider.dart';
import 'package:hmg_patient_app/uitl/app_shared_preferences.dart';
import 'package:hmg_patient_app/uitl/date_uitl.dart';
import 'package:hmg_patient_app/uitl/utils.dart';
import 'package:hmg_patient_app/widgets/in_app_browser/InAppBrowser.dart';
import 'package:flutter/cupertino.dart';

import 'mock_doctor_response.dart';

class DoctorsListService extends BaseService {
  AppSharedPreferences sharedPref = AppSharedPreferences();
  AppGlobal appGlobal = new AppGlobal();

  AuthenticatedUser authUser = new AuthenticatedUser();
  AuthProvider authProvider = new AuthProvider();

  double? lat;
  double? long;
  String? deviceToken;
  String? tokenID;
  List<LaserBodyPart> selectedBodyPartList = [];

  Future<Map> getDoctorsList(int clinicID, int projectID, bool isNearest, int languageID, BuildContext? context, {doctorId, doctorName, isContinueDentalPlan = false}) async {
    Map<String, dynamic> request;

    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    if (await this.sharedPref.getDouble(USER_LAT) != null && await this.sharedPref.getDouble(USER_LONG) != null) {
      lat = await this.sharedPref.getDouble(USER_LAT);
      long = await this.sharedPref.getDouble(USER_LONG);
    }

    // Request req = appGlobal.getPublicRequest();
    request = {
      //
      // "IPAdress": "10.20.10.20",
      // "VersionID": req.VersionID,
      // "Channel": req.Channel,
      // "generalid": 'Cs2020@2016\$2958',
      "PatientOutSA": authProvider.isLogin ? authUser.outSA : 0,
      "TokenID": "",
      // "DeviceTypeID": req.DeviceTypeID,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "ClinicID": clinicID,
      "ProjectID": projectID,
      "DoctorName": doctorName, //!= null ? doctorId : 0,
      "ContinueDentalPlan": isContinueDentalPlan,
      "IsSearchAppointmnetByClinicID": isContinueDentalPlan ? false : true,
      "PatientID": authUser.patientID != null ? authUser.patientID : 0,
      "gender": authUser.gender != null ? authUser.gender : 0,
      "age": authUser.age != null ? authUser.age : 0,
      "DateofBirth": authUser.dateofBirth != null ? authUser.dateofBirth : null,
      "IsGetNearAppointment": false,
      "SearchForVoiceCommand": doctorId != null && doctorId.length > 0 ? true : false,
      "DoctorIDsList": doctorId,
      "Latitude": lat != null ? lat.toString() : 0,
      "Longitude": long != null ? long.toString() : 0,
      "isDentalAllowedBackend": clinicID == 17 ? true : isContinueDentalPlan,
      "IsGetNearAppointment": isNearest,
      "LanguageID": languageID,
      if (isNearest) "SelectedDate": DateUtil.convertDateToString(DateTime.now()),
      "License": true
    };

    dynamic localRes;

    await baseAppClient.post(GET_DOCTORS_LIST_URL, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getDoctorsListByName(String docName, int languageID, BuildContext context) async {
    Map<String, dynamic> request;

    late double lat = 0.0;
    late double long = 0.0;

    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    if (await this.sharedPref.getDouble(USER_LAT) != null && await this.sharedPref.getDouble(USER_LONG) != null) {
      lat = await this.sharedPref.getDouble(USER_LAT);
      long = await this.sharedPref.getDouble(USER_LONG);
    }

    Request req = appGlobal.getPublicRequest();
    request = {
      "IPAdress": "10.20.10.20",
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "generalid": 'Cs2020@2016\$2958',
      "PatientOutSA": authProvider.isLogin ? authUser.outSA : false,
      "TokenID": "",
      "DeviceTypeID": req.DeviceTypeID,
      "SessionID": null,
      "ClinicID": 0,
      "ProjectID": 0,
      "ContinueDentalPlan": false,
      "IsSearchAppointmnetByClinicID": false,
      "DoctorName": docName,
      "DateofBirth": authUser.dateofBirth != null ? authUser.dateofBirth : null,
      "PatientID": authUser.patientID != null ? authUser.patientID : 0,
      "gender": authUser.gender != null ? authUser.gender : 0,
      "age": authUser.age != null ? authUser.age : 0,
      "IsGetNearAppointment": false,
      "Latitude": lat == null ? 0.0 : lat,
      "Longitude": long == null ? 0.0 : long,
      "LanguageID": languageID,
      "License": true
    };

    dynamic localRes = response;

    await baseAppClient.post(GET_DOCTORS_LIST_URL,
        onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getDoctorsProfile(int docID, int clinicID, int projectID, int languageID, context) async {
    Map<String, dynamic> request;

    Request req = appGlobal.getPublicRequest();
    request = {
      "IPAdress": "10.20.10.20",
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "generalid": 'Cs2020@2016\$2958',
      "PatientOutSA": authUser.outSA ?? false,
      "TokenID": "",
      "DeviceTypeID": req.DeviceTypeID,
      "SessionID": null,
      "doctorID": docID,
      "ClinicID": clinicID,
      "PatientID": 0,
      "License": true,
      "IsRegistered": true,
      "ProjectID": projectID,
      "isDentalAllowedBackend": false,
      "LanguageID": languageID,
    };

    dynamic localRes;

    await baseAppClient.post(GET_DOCTOR_PROFILE, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getDoctorsRating(int docID, int languageID, context) async {
    Map<String, dynamic> request;

    Request req = appGlobal.getPublicRequest();
    request = {
      "IPAdress": "10.20.10.20",
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "generalid": 'Cs2020@2016\$2958',
      "PatientOutSA": authUser.outSA,
      "TokenID": "",
      "DeviceTypeID": req.DeviceTypeID,
      "SessionID": null,
      "doctorID": docID,
      "PatientID": 0,
      "License": true,
      "IsRegistered": true,
      "LanguageID": languageID,
      "isDentalAllowedBackend": false
    };

    dynamic localRes;

    await baseAppClient.post(GET_DOCTOR_RATING_NOTES, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<DoctorPrePostImages> getDoctorPrePostImages(DoctorProfileList doctorProfile, context) async {
    Map<String, dynamic> request;
    request = {"PatientOutSA": authUser.outSA ?? 0, "isDentalAllowedBackend": false, "DoctorID": doctorProfile.doctorID, "ClinicID": doctorProfile.clinicID, "ProjectID": doctorProfile.projectID};

    var images = DoctorPrePostImages();
    await baseAppClient.post(GET_DOCTOR_PRE_POST_IMAGES, onSuccess: (response, statusCode) async {
      var list = response['DoctorPrePostImagesList'];
      if (list is List && list.length > 0) {
        list.forEach((j) {
          var image = DoctorPrePostImageModel.fromJson(j);
          if (image.imageType == 1) images.pre = image;
          if (image.imageType == 2) images.post = image;
        });
      }
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(images);
  }

  Future<Map> getDoctorsRatingDetails(int docID, int languageID, context) async {
    Map<String, dynamic> request;

    Request req = appGlobal.getPublicRequest();
    request = {
      "IPAdress": "10.20.10.20",
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "generalid": 'Cs2020@2016\$2958',
      "PatientOutSA": authUser.outSA,
      "TokenID": "",
      "DeviceTypeID": req.DeviceTypeID,
      "SessionID": null,
      "DoctorID": docID,
      "PatientID": 0,
      "License": true,
      "IsRegistered": true,
      "LanguageID": languageID,
      "isDentalAllowedBackend": false
    };

    dynamic localRes;

    await baseAppClient.post(GET_DOCTOR_RATING_DETAILS, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getDoctorFreeSlots(int docID, int clinicID, int projectID, bool isContinueDentalPlan, BuildContext context, [ProjectViewModel? projectViewModel]) async {
    Map<String, dynamic> request;

    Request req = appGlobal.getPublicRequest();
    request = {
      "DoctorID": docID,
      "IsBookingForLiveCare": 0,
      "ClinicID": clinicID,
      "ProjectID": projectID,
      "OriginalClinicID": clinicID,
      "days": 0,
      "isReschadual": false,
      "VersionID": req.VersionID,
      "Channel": 3,
      "IPAdress": "10.20.10.20",
      "generalid": "Cs2020@2016\$2958",
      "PatientOutSA": authProvider.isLogin ? authUser.outSA : 0,
      "SessionID": null,
      "isDentalAllowedBackend": false,
      "LanguageID": 1,
      "DeviceTypeID": 1,
      "ContinueDentalPlan": isContinueDentalPlan,
    };

    if (clinicID == 253) {
      List<String> procedureID = projectViewModel!.selectedBodyPartList.map((element) => element.id.toString()).toList();
      request["GeneralProcedureList"] = procedureID;
      if (procedureID.length == 1 && procedureID[0] == "1") {
        request["ProcedureSlotDuration"] = 90;
      } else {
        request["ProcedureSlotDuration"] = projectViewModel.laserSelectionDuration;
      }
    }

    dynamic localRes;

    await baseAppClient.post(GET_DOCTOR_FREE_SLOTS, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getDoctorScheduledFreeSlots(int docID, int clinicID, int projectID, int serviceID, BuildContext context) async {
    Map<String, dynamic> request;

    Request req = appGlobal.getPublicRequest();
    request = {
      "DoctorID": docID,
      "IsBookingForLiveCare": 1,
      "ClinicID": clinicID,
      "ProjectID": projectID,
      "OriginalClinicID": clinicID,
      "ServiceID": serviceID,
      "days": 50,
      "isReschadual": false,
      "VersionID": req.VersionID,
      "Channel": 3,
      "IPAdress": "10.20.10.20",
      "generalid": "Cs2020@2016\$2958",
      "PatientOutSA": authUser.outSA,
      "SessionID": null,
      "isDentalAllowedBackend": false,
      "LanguageID": 1,
      "DeviceTypeID": 1
    };

    dynamic localRes;

    await baseAppClient.post(GET_LIVECARE_SCHEDULE_DOCTOR_TIME_SLOTS, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> insertWalkInAppointment(int docID, int clinicID, int projectID, String selectedTime, String selectedDate, int initialSlotDuration, int languageID, BuildContext context) async {
    Map<String, dynamic> request;

    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    Request req = appGlobal.getPublicRequest();
    request = {
      "IsForLiveCare": false,
      "ProjectID": projectID,
      "ClinicID": clinicID,
      "DoctorID": docID,
      "StartTime": selectedTime,
      "SelectedTime": selectedTime,
      "EndTime": selectedTime,
      "InitialSlotDuration": initialSlotDuration,
      "StrAppointmentDate": selectedDate,
      "IsVirtual": false,
      "DeviceType": Platform.isIOS ? 'iOS' : 'Android',
      "BookedBy": 102,
      "VisitType": 1,
      "VisitFor": 1,
      "GenderID": authUser.gender,
      "Age": authUser.age != null ? authUser.age : 0,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType
    };

    dynamic localRes;
    try {
      await baseAppClient.post(INSERT_WALKIN_APPOINTMENT, onSuccess: (response, statusCode) async {
        localRes = response;
      }, onFailure: (String error, int statusCode) {
        throw error;
      }, body: request);
      return Future.value(localRes);
    } catch (e) {
      return Future.error(e);
    }
  }

  Future<Map> insertAppointment(int docID, int clinicID, int projectID, String selectedTime, String selectedDate, int initialSlotDuration, int languageID, BuildContext context,
      [String? procedureID, num? testTypeEnum, num? testProcedureEnum, ProjectViewModel? projectViewModel, int? invoiceNumber, int? lineItemNo, String? invoiceNoVP]) async {
    Map<String, dynamic> request;

    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    Request req = appGlobal.getPublicRequest();
    request = {
      "IsForLiveCare": false,
      "ProjectID": projectID,
      "ClinicID": clinicID,
      "DoctorID": docID,
      "StartTime": selectedTime,
      "SelectedTime": selectedTime,
      "EndTime": selectedTime,
      "ProcedureID": procedureID,
      "TestTypeEnum": testTypeEnum,
      "TestProcedureEnum": testProcedureEnum,
      "InitialSlotDuration": initialSlotDuration,
      "StrAppointmentDate": selectedDate,
      "IsVirtual": false,
      "DeviceType": Platform.isIOS ? 'iOS' : 'Android',
      "BookedBy": 102,
      "VisitType": 1,
      "VisitFor": 1,
      "GenderID": authUser.gender,
      "Age": authUser.age != null ? authUser.age : 0,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType,
      "InvoiceNo": invoiceNumber,
      "InvoiceNo_VP": invoiceNoVP,
      "LineItemNo": lineItemNo,
      // "TokenID":"@dm!n"
    };

    if (clinicID == 253) {
      List<String> procedureID = projectViewModel!.selectedBodyPartList.map((element) => element.id.toString()).toList();
      request["GeneralProcedureList"] = procedureID;
      if (procedureID.length == 1 && procedureID[0] == "1") {
        request["InitialSlotDuration"] = 90;
      } else {
        request["InitialSlotDuration"] = projectViewModel.laserSelectionDuration;
      }
    }

    dynamic localRes;
    try {
      await baseAppClient.post(INSERT_SPECIFIC_APPOINTMENT, onSuccess: (response, statusCode) async {
        localRes = response;
      }, onFailure: (String error, int statusCode) {
        throw error;
      }, body: request);
      return Future.value(localRes);
    } catch (e) {
      return Future.error(e);
    }
  }

  Future<Map> insertLiveCareScheduleAppointment(int docID, int clinicID, int projectID, int serviceID, String selectedTime, String selectedDate, int languageID, BuildContext context) async {
    Map<String, dynamic> request;

    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    Request req = appGlobal.getPublicRequest();
    request = {
      "IsForLiveCare": true,
      "ProjectID": projectID,
      "ClinicID": clinicID,
      "DoctorID": docID,
      "ServiceID": serviceID,
      "StartTime": selectedTime,
      "SelectedTime": selectedTime,
      "EndTime": selectedTime,
      "InitialSlotDuration": 0,
      "StrAppointmentDate": selectedDate,
      "IsVirtual": false,
      "DeviceType": Platform.isIOS ? 'iOS' : 'Android',
      "DeviceToken": await sharedPref.getString(PUSH_TOKEN),
      "BookedBy": 102,
      "VisitType": 1,
      "VisitFor": 1,
      "Age": authUser.age != null ? authUser.age : 0,
      "GenderID": authUser.gender,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType
    };

    dynamic localRes;

    await baseAppClient.post(INSERT_LIVECARE_SCHEDULE_APPOINTMENT, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getPatientShare(String appoID, int clinicID, int projectID, int languageID, BuildContext context) async {
    Map<String, dynamic> request;

    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    Request req = appGlobal.getPublicRequest();

    request = {
      "ProjectID": projectID,
      "ClinicID": clinicID,
      "AppointmentNo": appoID,
      "IsActiveAppointment": true,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "PatientTypeID": authUser.patientType,
      "LanguageID": languageID,
      "PatientType": authUser.patientType
    };

    dynamic localRes;

    await baseAppClient.post(GET_PATIENT_SHARE, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> setOnlineCheckInForAppointment(String appoID, int projectID, int languageID, BuildContext context) async {
    Map<String, dynamic> request;

    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }
    request = {"ProjectID": projectID, "AppointmentNo": appoID, "LanguageID": languageID};

    dynamic localRes;

    await baseAppClient.post(SET_ONLINE_CHECKIN_FOR_APPOINTMENT, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> checkPatientHasDermaPackage(int patientID, int clinicID, int projectID, int doctorID, int languageID, BuildContext context) async {
    Map<String, dynamic> request;

    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }
    request = {"PatientID": patientID, "ClinicID": clinicID, "ProjectID": projectID, "LanguageID": languageID};
    //request = { "PatientID":4768732, "ClinicID":1, "ProjectID": 15, "LanguageID": languageID, "TokenID":"@dm!n" };

    dynamic localRes;

    await baseAppClient.post(CHECK_PATIENT_DERMA_PACKAGE, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getLiveCareAppointmentPatientShare(String appoID, int clinicID, int projectID, int languageID, BuildContext context) async {
    Map<String, dynamic> request;

    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    Request req = appGlobal.getPublicRequest();

    request = {
      "ProjectID": projectID,
      "ClinicID": clinicID,
      "AppointmentNo": appoID,
      "IsActiveAppointment": true,
      "IsForLiveCare": true,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "PatientTypeID": authUser.patientType,
      "LanguageID": languageID,
      "PatientType": authUser.patientType
    };

    dynamic localRes;

    await baseAppClient.post(GET_PATIENT_SHARE_LIVECARE, onSuccess: (response, statusCode) async {
      localRes = response['OnlineCheckInAppointments'][0];
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getOBGyneOrdersList(BuildContext context) async {
    Map<String, dynamic> request;

    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    Request req = appGlobal.getPublicRequest();

    request = {"ProjectID": 15, "DeviceTypeID": req.DeviceTypeID, "PatientID": authUser.patientID, "PatientTypeID": authUser.patientType, "PatientType": authUser.patientType};

    dynamic localRes;

    await baseAppClient.post(GET_OBGYNE_ORDERS_LIST, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getOBGyneDoctorsList(int projectID, String setupID, int languageID, BuildContext context) async {
    Map<String, dynamic> request;

    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    Request req = appGlobal.getPublicRequest();

    request = {
      "ProjectID": projectID,
      "SetupID": setupID,
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "PatientTypeID": authUser.patientType,
      "LanguageID": languageID,
      "PatientType": authUser.patientType
    };

    dynamic localRes;

    await baseAppClient.post(GET_OBGYNE_DOCTORS_LIST, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getPatientAppointmentHistoryWithAppoNo(int appoNo, int languageID) async {
    Map<String, dynamic> request;
    request = {"IsActiveAppointment": true, "AppointmentNo": appoNo, "IsComingFromCOC": false, "LanguageID": languageID};
    dynamic localRes;
    await baseAppClient.post(GET_PATIENT_APPOINTMENT_HISTORY, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);

    return Future.value(localRes);
  }

  Future<Map> getPatientShareForWalkInAppointment(int clinicID, int projectID, int doctorID) async {
    Map<String, dynamic> request;
    request = {"ProjectID": projectID, "ClinicID": clinicID, "DoctorID": doctorID};
    dynamic localRes;
    await baseAppClient.post(GET_PATIENT_SHARE_FOR_WALKIN_APPOINTMENT, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);

    return Future.value(localRes);
  }

  Future<Map> canPayForWalkInAppointment(int clinicID, int projectID, int doctorID) async {
    Map<String, dynamic> request;
    request = {"ProjectID": projectID, "ClinicID": clinicID, "DoctorID": doctorID, "StartTime": "12:00", "EndTime": "12:00"};
    dynamic localRes;
    await baseAppClient.post(CAN_PAY_FOR_FOR_WALKIN_APPOINTMENT, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);

    return Future.value(localRes);
  }

  Future<Map> getPatientAppointmentHistory(bool isActiveAppointment, int languageID, BuildContext context, {bool isForCOC = false, isForUpcomming = false, IsForArrived = false}) async {
    Map<String, dynamic> request;

    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    Request req = appGlobal.getPublicRequest();

    request = {
      "IsActiveAppointment": isActiveAppointment,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "PatientTypeID": authUser.patientType,
      "IsComingFromCOC": isForCOC,
      "PatientType": authUser.patientType,
      "LanguageID": languageID,
      "isForUpcomming": isForUpcomming,
      "IsForArrived": IsForArrived
    };

    dynamic localRes;

    await baseAppClient.post(GET_PATIENT_APPOINTMENT_HISTORY, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getPatientAppointmentCurfewHistory(bool isActiveAppointment) async {
    Map<String, dynamic> request;

    Request req = appGlobal.getPublicRequest();

    request = {
      "IsActiveAppointment": isActiveAppointment,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": 1231755,
      "PatientTypeID": 1,
      "PatientType": 1
    };

    dynamic localRes;

    await baseAppClient.post(GET_PATIENT_APPOINTMENT_CURFEW_HISTORY, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> confirmAppointment(int appoNo, int clinicID, int projectID, bool isLiveCare, BuildContext context) async {
    Map<String, dynamic> request;

    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    Request req = appGlobal.getPublicRequest();

    request = {
      "AppointmentNumber": appoNo,
      "IsLiveCareAppointment": isLiveCare,
      "ClinicID": clinicID,
      "ProjectID": projectID,
      "ConfirmationBy": 102,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType
    };

    dynamic localRes;

    await baseAppClient.post(CONFIRM_APPOINTMENT, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> insertVIDARequest(int appoNo, int clinicID, int projectID, int serviceID, int docID, String appoDate, String clientRequestID, int languageID, BuildContext context) async {
    Map<String, dynamic> request;

    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    deviceToken = await sharedPref.getString(PUSH_TOKEN);

    if (await this.sharedPref.getDouble(USER_LAT) != null && await this.sharedPref.getDouble(USER_LONG) != null) {
      lat = await this.sharedPref.getDouble(USER_LAT);
      long = await this.sharedPref.getDouble(USER_LONG);
    }

    Request req = appGlobal.getPublicRequest();

    request = {
      "AppointmentNo": appoNo,
      "AppointmentDate": appoDate,
      "ClientRequestID": clientRequestID,
      "ClinicID": clinicID,
      "ProjectID": projectID,
      "ServiceID": serviceID,
      "AcceptedBy": docID,
      "IsFlutter": true,
      "DeviceToken": deviceToken,
      "Latitude": lat,
      "Longitude": long,
      "DeviceType": req.DeviceType,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType,
      "VoipToken": await sharedPref.getString(ONESIGNAL_APNS_TOKEN),
      "LanguageID": languageID,
      "IsVoip": Platform.isIOS ? true : false
    };

    dynamic localRes;

    await baseAppClient.post(INSERT_VIDA_REQUEST, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> cancelAppointment(AppoitmentAllHistoryResultList appo, BuildContext context, {bool isReschedule = false}) async {
    Map<String, dynamic> request;

    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    Request req = appGlobal.getPublicRequest();

    request = {
      "AppointmentID": appo.appointmentNo,
      "ClinicID": appo.clinicID,
      "ProjectID": appo.projectID,
      "CancelToReschadual": isReschedule,
      "EndTime": appo.endTime,
      "StartTime": appo.startTime,
      "DoctorID": appo.doctorID,
      "IsForLiveCare": appo.isLiveCareAppointment,
      "OriginalClinicID": appo.originalClinicID,
      "OriginalProjectID": appo.originalProjectID,
      "StrAppointmentDate": DateUtil.getDateFormatted(appo.appointmentDate!),
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "PatientTypeID": authUser.patientType,
      // "LanguageID": 1,
      "PatientType": authUser.patientType
    };

    dynamic localRes;

    await baseAppClient.post(CANCEL_APPOINTMENT, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> generateAppointmentQR(PatientShareResponse patientShareResponse, BuildContext context) async {
    Map<String, dynamic> request;

    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    Request req = appGlobal.getPublicRequest();

    request = {
      "AppointmentNo": patientShareResponse.appointmentNo,
      "ClinicID": patientShareResponse.clinicID,
      "ProjectID": patientShareResponse.projectID,
      "IsFollowup": patientShareResponse.isFollowup,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "PatientTypeID": authUser.patientType,
      "LanguageID": 1,
      "PatientType": authUser.patientType
    };

    dynamic localRes;

    await baseAppClient.post(GENERATE_QR_APPOINTMENT, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> sendAppointmentQREmail(String to, String appoDate, String appoNo, String docName, String projName, String QR, String speciality, BuildContext context) async {
    Map<String, dynamic> request;

    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    Request req = appGlobal.getPublicRequest();

    request = {
      "AppointmentNo": appoNo,
      "AppointmentDate": appoDate,
      "DoctorName": docName,
      "ProjectName": projName,
      "QR": QR,
      "Speciality": speciality,
      "To": to,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType
    };

    dynamic localRes;

    await baseAppClient.post(EMAIL_QR_APPOINTMENT, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> checkPaymentStatus(String transactionID, bool isPharma, BuildContext context) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    Request req = appGlobal.getPublicRequest();
    request = {
      "ClientRequestID": transactionID,
      "IsPharmacy": isPharma,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "PatientTypeID": authUser.patientType,
      "LanguageID": 1,
      "PatientType": authUser.patientType
    };
    dynamic localRes;
    await baseAppClient.post(CHECK_PAYMENT_STATUS, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future getTamaraPaymentStatus(String orderID) async {
    hasError = false;
    dynamic localRes;
    await baseAppClient.get(GET_TAMARA_PAYMENT_STATUS + "$orderID", isRCService: false, isExternal: true, onSuccess: (dynamic response, int statusCode) {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    });
    return Future.value(localRes);
  }

  Future<Map> addAdvancedNumberRequest(String advanceNumber, String paymentReference, dynamic appointmentID, BuildContext context) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    Request req = appGlobal.getPublicRequest();
    request = {
      "AdvanceNumber": advanceNumber,
      "AdvanceNumber_VP": advanceNumber,
      "PaymentReferenceNumber": paymentReference,
      "AppointmentID": appointmentID,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "PatientTypeID": authUser.patientType,
      "LanguageID": 1,
      "PatientType": authUser.patientType
    };
    dynamic localRes;
    await baseAppClient.post(ADD_ADVANCE_NUMBER_REQUEST, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request, isAllowAny: true);
    return Future.value(localRes);
  }

  Future<Map> addVIDARequest(String advanceNumber, String paymentReference, dynamic apptData, BuildContext context) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    Request req = appGlobal.getPublicRequest();
    request = {
      "AdvanceNumber": advanceNumber,
      "PaymentReferenceNumber": paymentReference,
      "AppointmentNo": apptData.AppointmentNo,
      "AcceptedBy": apptData.DoctorID,
      "ServiceID": apptData.ServiceID,
      "ProjectID": apptData.ProjectID,
      "ClinicID": apptData.ClinicID,
      "ClientRequestID": Utils.getAppointmentTransID(apptData.ProjectID, apptData.ClinicID, apptData.AppointmentNo),
      "AppointmentDate": apptData.AppointmentDate,
      "DeviceType": Platform.isIOS ? "iOS" : "Android",
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType,
      "DeviceToken": await sharedPref.getString(PUSH_TOKEN),
      "VoipToken": await sharedPref.getString(ONESIGNAL_APNS_TOKEN),
      "LanguageID": 1,
      "IsVoip": Platform.isIOS ? true : false
    };

    // request.DeviceToken = this.cs.sharedService.getSharedData(AuthenticationService.DEVICE_TOKEN, false);
    // request.Latitude = this.cs.szharedService.getSharedData('userLat', false);
    // request.Longitude = this.cs.sharedService.getSharedData('userLong', false);
    // request.ServiceID = apptData.ServiceID;
    // request.ProjectID = apptData.ProjectID;
    // request.ClinicID = apptData.ClinicID;
    // request.ClientRequestID = AppointmentModel.getAppointmentTransID(apptData);
    // request.AppointmentDate = apptData.AppointmentDate;
    // request.DeviceType = this.getDeviceType();
    // request.VoipToken = this.platform.is('ios') ? this.cs.sharedService.getSharedData(AuthenticationService.APNS_TOKEN, false) : "";
    dynamic localRes;
    await baseAppClient.post(ADD_VIDA_REQUEST, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> autoGenerateAncillaryOrdersInvoice(dynamic orderNo, int projectID, dynamic appointmentID, List<dynamic> selectedProcListAPI, int languageID, BuildContext context) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    List<String> procedureOrderIDs = [];

    selectedProcListAPI.forEach((element) {
      procedureOrderIDs.add(element["ProcedureID"]);
    });

    request = {
      "LanguageID": languageID,
      "RequestAncillaryOrderInvoice": [
        {"MemberID": 102, "ProjectID": projectID, "AppointmentNo": appointmentID, "OrderNo": orderNo, "AncillaryOrderInvoiceProcList": selectedProcListAPI}
      ],
      "ProcedureOrderIds": procedureOrderIDs
    };
    dynamic localRes;
    await baseAppClient.post(GENERATE_ANCILLARY_ORDERS_INVOICE, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> isAllowedToAskDoctor(int docID, int languageID, BuildContext context) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    Request req = appGlobal.getPublicRequest();
    request = {
      "IsForAskYourDoctor": true,
      "DoctorID": docID,
      "Top": 25,
      "beforeDays": 15,
      "exludType": 4,
      "LanguageID": languageID,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType
    };

    dynamic localRes;
    await baseAppClient.post(IS_ALLOW_ASK_DOCTOR, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getCallRequestType(int languageID, BuildContext context) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    Request req = appGlobal.getPublicRequest();
    request = {
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "PatientTypeID": authUser.patientType,
      "LanguageID": languageID,
      "PatientType": authUser.patientType
    };

    dynamic localRes;
    await baseAppClient.post(GET_CALL_REQUEST_TYPE, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> sendAskDocCallRequest(AppoitmentAllHistoryResultList appo, String requestType, int languageID, BuildContext context) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    Request req = appGlobal.getPublicRequest();

    request = {
      "ProjectID": appo.projectID,
      "SetupID": appo.setupID,
      "DoctorID": appo.doctorID,
      "ClinicID": appo.clinicID,
      "RequestType": requestType,
      "RequestTypeID": requestType,
      "PatientMobileNumber": authUser.mobileNumber,
      "IsMessageSent": false,
      "RequestDate": DateUtil.getYearMonthDayHourMinSecDateFormatted(DateTime.now()).split(" ")[0],
      "RequestTime": DateUtil.getYearMonthDayHourMinSecDateFormatted(DateTime.now()).split(" ")[1],
      "Remarks": "",
      "Status": 1,
      "CreatedBy": 102,
      "CreatedOn": DateUtil.getYearMonthDayHourMinSecDateFormatted(DateTime.now()).split(" ")[0],
      "EditedBy": 102,
      "EditedOn": DateUtil.getYearMonthDayHourMinSecDateFormatted(DateTime.now()).split(" ")[0],
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "PatientTypeID": authUser.patientType,
      "LanguageID": languageID,
      "PatientType": authUser.patientType
    };

    dynamic localRes;
    await baseAppClient.post(SEND_CALL_REQUEST, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getPatientRadOrders(String appoNo, int projectID, int languageID, BuildContext context) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    Request req = appGlobal.getPublicRequest();
    request = {
      "AppointmentNo": appoNo,
      "ProjectID": projectID,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "PatientTypeID": authUser.patientType,
      "LanguageID": languageID,
      "PatientType": authUser.patientType
    };

    dynamic localRes;
    await baseAppClient.post(GET_PATIENT_ORDERS, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getPatientLabOrdersByAppoNo(dynamic appoNo, dynamic projID, dynamic clinicID, int languageID, BuildContext context) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    Request req = appGlobal.getPublicRequest();
    request = {
      "AppointmentNo": appoNo,
      "ProjectID": projID,
      "ClinicID": clinicID,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "PatientTypeID": authUser.patientType,
      "LanguageID": languageID,
      "PatientType": authUser.patientType
    };

    dynamic localRes;
    await baseAppClient.post(GET_PATIENT_LAB_ORDERS_BY_APPOINTMENT, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getPatientPrescriptionReports(AppoitmentAllHistoryResultList appo, int languageID, BuildContext context) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    Request req = appGlobal.getPublicRequest();
    request = {
      "AppointmentNo": appo.appointmentNo,
      "ClinicID": appo.clinicID,
      "ProjectID": appo.projectID,
      "EpisodeID": appo.episodeID,
      "VersionID": req.VersionID,
      "SetupID": appo.setupID,
      "Channel": req.Channel,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "PatientTypeID": authUser.patientType,
      "LanguageID": languageID,
      "PatientType": authUser.patientType
    };

    dynamic localRes;
    await baseAppClient.post(GET_PRESCRIPTION_REPORT_ENH, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> sendPrescriptionEmail(String appoDate, String setupId, int languageID, dynamic prescriptionReportEnhList, bool isDownload, BuildContext context) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    Request req = appGlobal.getPublicRequest();
    request = {
      "AppointmentDate": appoDate,
      "DateofBirth": authUser.dateofBirth,
      "ListPrescriptions": prescriptionReportEnhList,
      "PatientIditificationNum": authUser.patientIdentificationNo,
      "PatientMobileNumber": authUser.mobileNumber,
      "PatientName": authUser.firstName! + " " + authUser.lastName!,
      "To": authUser.emailAddress,
      "SetupID": setupId,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "PatientTypeID": authUser.patientType,
      "LanguageID": authUser.patientType,
      "PatientType": authUser.patientType,
      "IsDownload": isDownload,

    };

    dynamic localRes;
    await baseAppClient.post(SEND_PRESCRIPTION_EMAIL, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> createAdvancePayment(AppoitmentAllHistoryResultList appo, String projectID, double payedAmount, String paymentReference, String paymentMethodName, BuildContext context) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    Request req = appGlobal.getPublicRequest();
    request = {
      "ProjectID": projectID,
      "OnlineCheckInAppointment": {
        "AppointmentNo": appo != null ? appo.appointmentNo.toString() : "0",
        "PaymentMethodName": paymentMethodName,
        "PaymentAmount": payedAmount == 0 ? "0" : payedAmount.toString(),
        "PaymentDate": payedAmount == 0 ? "" : "/Date(" + DateTime.now().millisecondsSinceEpoch.toString() + ")/",
        "PaymentReferenceNumber": payedAmount == 0 ? "" : paymentReference,
        "ProjectID": appo != null ? appo.projectID.toString() : projectID,
        "PatientID": authUser.patientID,
        "ClinicID": appo != null ? appo.clinicID : "0",
        "UserID": authUser.patientID,
        "Status": authUser.patientType
      },
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "PatientID": authUser.patientID,
      "PatientTypeID": authUser.patientType,
      "LanguageID": 1,
      "PatientType": authUser.patientType
    };
    dynamic localRes;
    await baseAppClient.post(CREATE_ADVANCE_PAYMENT, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> HIS_createAdvancePayment(AppoitmentAllHistoryResultList appo, String projectID, double payedAmount, String paymentReference, String paymentMethodName, dynamic patientType,
      String patientName, dynamic patientID, BuildContext context,
      {bool isAncillaryOrder = false, int clinicID = 0}) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    Request req = appGlobal.getPublicRequest();

    request = {
      "CustName": patientName,
      "CustID": patientID,
      "SetupID": "010266",
      "ProjectID": projectID,
      "PatientID": patientID,
      "AccountID": patientID,
      "PaymentAmount": payedAmount,
      "NationalityID": null,
      "DepositorName": authUser.firstName! + " " + authUser.lastName!,
      "CreatedBy": 3,
      "PaymentMethodName": paymentMethodName,
      "PaymentReference": paymentReference,
      "PaymentMethod": paymentMethodName,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "LanguageID": 1,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "PatientTypeID": patientType,
      "IsAncillaryOrder": isAncillaryOrder,
      // "AncillaryProcedureList": ancillaryOrdersProcedureList,
      "PatientType": patientType
    };
    dynamic localRes;
    await baseAppClient.post(HIS_CREATE_ADVANCE_PAYMENT, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> ER_createAdvancePayment(AppoitmentAllHistoryResultList appo, String projectID, double payedAmount, String paymentReference, String paymentMethodName, BuildContext context) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    Request req = appGlobal.getPublicRequest();

    request = {
      // "VersionID": req.VersionID,
      // "Channel": req.Channel,
      // "IPAdress": req.IPAdress,
      // "generalid": req.generalid,
      // "PatientOutSA": authUser.outSA,
      // "PatientTypeID": authUser.patientType,
      "LanguageID": 1,
      "ERAdvanceAmount": {
        "ProjectId": projectID,
        "PatientId": authUser.patientID,
        "ClinicId": 10,
        "DepositorName": authUser.firstName! + " " + authUser.lastName!,
        "MemberId": authUser.patientID,
        "NationalityID": authUser.nationalityID,
        "PaymentAmount": payedAmount,
        "PaymentDate": DateUtil.convertDateToString(DateTime.now()),
        "PaymentMethodName": paymentMethodName,
        "PaymentReferenceNumber": paymentReference,
        "SourceType": 2
      }
    };
    dynamic localRes;
    await baseAppClient.post(ER_CREATE_ADVANCE_PAYMENT, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> ER_InsertEROnlinePaymentDetails(
      AppoitmentAllHistoryResultList appo, String projectID, double payedAmount, String paymentReference, String paymentMethodName, BuildContext context) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    Request req = appGlobal.getPublicRequest();

    request = {
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "PatientTypeID": authUser.patientType,
      "LanguageID": 1,
      "EROnlineCheckinPaymentDetails": {
        "CheckinDate": DateUtil.convertDateToString(DateTime.now()),
        "ExpectedArrivalTime": DateUtil.convertDateToString(DateTime.now()),
        "ProjectId": projectID,
        "PatientId": authUser.patientID,
        "ClinicId": 10,
        "FormId": 15,
        "DepositorName": authUser.firstName! + " " + authUser.lastName!,
        "MemberId": authUser.patientID,
        "NationalityID": authUser.nationalityID,
        "PaymentAmount": payedAmount,
        "PaymentDate": DateUtil.convertDateToString(DateTime.now()),
        "PaymentMethodName": paymentMethodName,
        "PaymentReferenceNumber": paymentReference,
        "TriageScore": await sharedPref.getInt(ER_CHECKIN_RISK_SCORE)
      }
    };
    dynamic localRes;
    await baseAppClient.post(ER_INSERT_ADVANCE_PAYMENT, onSuccess: (response, statusCode) async {
      localRes = response;
      sharedPref.remove(ER_CHECKIN_RISK_SCORE);
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getPatientHealthDataStats(int medCategoryId, int medCategoryStsId, BuildContext context) async {
    Map<String, dynamic> request;
    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    Request req = appGlobal.getPublicRequest();
    request = {
      "MedCategoryID": medCategoryId,
      "MedGetStsID": medCategoryStsId,
      "VersionID": req.VersionID,
      "Channel": req.Channel,
      "IPAdress": req.IPAdress,
      "generalid": req.generalid,
      "PatientOutSA": authUser.outSA,
      "SessionID": "YckwoXhUmWBsnHKEKig",
      "isDentalAllowedBackend": false,
      "DeviceTypeID": req.DeviceTypeID,
      "PatientID": authUser.patientID,
      "PatientTypeID": authUser.patientType,
      "PatientType": authUser.patientType
    };
    dynamic localRes;
    await baseAppClient.post(GET_PATIENT_HEALTH_STATS, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> sendCheckinNfcRequest(int appointmentNo, String nfcCode, int projectId, int checkInBy, int clinicID, BuildContext context) async {
    Map<String, dynamic> request;

    request = {"AppointmentNo": appointmentNo, "NFC_Code": nfcCode, "ProjectID": projectId, "ClinicID": clinicID, "CheckinBy": checkInBy};
    dynamic localRes;
    await baseAppClient.post(SEND_CHECK_IN_NFC_REQUEST, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> checkScannedNFCAndQRCode(String nfcCode, int projectId) async {
    Map<String, dynamic> request;

    request = {"NFC_Code": nfcCode, "ProjectID": projectId};
    dynamic localRes;
    await baseAppClient.post(CHECK_SCANNED_NFC_QR_CODE, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> checkIfHasDentalPlan(int projectID, BuildContext context) async {
    Map<String, dynamic> request;

    request = {
      "ProjectID": projectID,
      "LanguageID": 1,
    };
    dynamic localRes;
    await baseAppClient.post(HAS_DENTAL_PLAN, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getTamaraPaymentDetails(BuildContext context) async {
    dynamic localRes;
    await baseAppClient.get(GET_TAMARA_PLAN, isExternal: true, onSuccess: (response, statusCode) async {
      localRes = response[0];
    }, onFailure: (String error, int statusCode) {
      throw error;
    });
    return localRes;
  }

  Future<Map> callPayfortApplePayAPI(ApplePayRequest applePayRequest, BuildContext context) async {
    Map<String, dynamic> request;

    request = {
      "currency": applePayRequest.currency,
      "language": applePayRequest.language,
      "customername": applePayRequest.customername,
      "customer_email": applePayRequest.customerEmail,
      "orderdescription": applePayRequest.orderdescription,
      "live_serviceid": applePayRequest.liveServiceid,
      "longitude": applePayRequest.longitude,
      "latitude": applePayRequest.latitude,
      "devicetoken": applePayRequest.devicetoken,
      "clientrequestid": applePayRequest.clientrequestid,
      "projectid": applePayRequest.projectid,
      "serviceid": applePayRequest.serviceid,
      "patientid": applePayRequest.patientid,
      "Amount": applePayRequest.amount,
      "apple_data": applePayRequest.appleData,
      "apple_signature": applePayRequest.appleSignature,
      "apple_header": {
        "apple_applicationData": "76a9a9cb2d9811e8de56d8e7713601bfa6acda3d488b1cf03b9b115bc3ff12b4",
        "apple_ephemeralPublicKey": applePayRequest.appleHeader!.appleEphemeralPublicKey!,
        "apple_publicKeyHash": applePayRequest.appleHeader!.applePublicKeyHash!,
        "apple_transactionId": applePayRequest.appleHeader!.appleTransactionId
      },
      "apple_paymentMethod": {
        "apple_displayName": applePayRequest.applePaymentMethod!.appleDisplayName,
        "apple_network": applePayRequest.applePaymentMethod!.appleNetwork,
        "apple_type": applePayRequest.applePaymentMethod!.appleType
      }
    };
    dynamic localRes;
    await baseAppClient.post(MyInAppBrowser.APPLE_PAY_PAYFORT_URL, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request, isExternal: true);
    return Future.value(localRes);
  }

  Future<Map> getLaserBodyPartsList(int laserCategoryID, int projectID, int languageID) async {
    Map<String, dynamic> request;

    request = {
      "LaserCategoryID": laserCategoryID,
      "ProjectID": projectID,
      "LanguageID": languageID,
    };
    dynamic localRes;
    await baseAppClient.post(LASER_BODY_PARTS, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> insertCovidQuestionnaire(List qa, int projectID, int testTypeEnum, int languageID, int testProcedureEnum) async {
    Map<String, dynamic> request;

    request = {
      "ProjectID": projectID,
      "LanguageID": languageID,
      "IsForTravel": qa[0]['ans'].toString(),
      "IsComingOutSA": qa[1]['ans'].toString(),
      "IsFeverCurrently": qa[2]['ans'].toString(),
      "IsFeverLast2Week": qa[3]['ans'].toString(),
      "IsSorethroat": qa[4]['ans'].toString(),
      "IsRunnyNose": qa[5]['ans'].toString(),
      "IsCough": qa[6]['ans'].toString(),
      "IsShortnessBreath": qa[7]['ans'].toString(),
      "IsNausea": qa[8]['ans'].toString(),
      "IsVomiting": qa[9]['ans'].toString(),
      "IsHeadache": qa[10]['ans'].toString(),
      "IsMusclePain": qa[11]['ans'].toString(),
      "IsJoinPain": qa[12]['ans'].toString(),
      "IsDiarrhea": qa[13]['ans'].toString(),
      "TestTypeEnum": testTypeEnum,
      "TestProcedureEnum": testProcedureEnum
    };

    dynamic localRes;
    await baseAppClient.post(INSERT_COVID_QUESTIONNAIRE, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> updateCovidQuestionnaire(String appoNo, int projectID, int testTypeEnum, int testProcedureEnum) async {
    Map<String, dynamic> request;

    request = {"AppointmentNo": appoNo, "ProjectID": projectID, "TestTypeEnum": testTypeEnum, "TestProcedureEnum": testProcedureEnum};

    dynamic localRes;
    await baseAppClient.post(UPDATE_COVID_QUESTIONNAIRE, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);

    return Future.value(localRes);
  }

  Future<Map> updateObGyneAppointment(int episodeID, int appointmentNo, int orderNo, String procedureId, int lineItemNo, int uniqueRowID, int languageID) async {
    Map<String, dynamic> request;

    request = {
      "EpisodeID": episodeID,
      "LanguageID": languageID,
      "AppointmentNo": appointmentNo,
      "OrderNo": orderNo,
      "ProcedureId": procedureId,
      "ProcedureAppointmentNo": appointmentNo,
      "LineItemNo": lineItemNo,
      "UniqueRowID": uniqueRowID
    };

    dynamic localRes;
    await baseAppClient.post(OBGYNE_PROCEDURE_UPDATE, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);

    return Future.value(localRes);
  }

  Future<Map> getRRTProcedures(int projectID, int languageID) async {
    Map<String, dynamic> request;

    request = {"ProjectID": projectID, "LanguageID": languageID};

    dynamic localRes;
    await baseAppClient.post(GET_RRT_PROCEDURE_LIST, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);

    return Future.value(localRes);
  }

  Future<Map> updateTamaraRequestStatus(String responseMessage, String status, String clientRequestID, String tamaraOrderID, num selectedInstallments) async {
    Map<String, dynamic> request = {
      "Response_Message": responseMessage,
      "ClientRequestID": clientRequestID,
      "Status": status,
      "FortID": tamaraOrderID, // Tamara order ID
      "LanguageID": 1,
      "Installments_Number": selectedInstallments
    };

    dynamic localRes;
    await baseAppClient.post(UPDATE_TAMARA_STATUS, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request, isAllowAny: true);

    return Future.value(localRes);
  }

  Future<Map> markAppointmentForTamara(int projectID, String appoNo) async {
    Map<String, dynamic> request;
    request = {"ProjectID": projectID, "AppointmentNo": appoNo, "LanguageID": 1};
    dynamic localRes;
    await baseAppClient.post(MARK_APPOINTMENT_TAMARA_STATUS, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);

    return Future.value(localRes);
  }

  Future<Map> autoGenerateInvoiceTamara(int projectID, String appoNo, String mobileNo) async {
    Map<String, dynamic> request;
    request = {"ProjectID": projectID, "AppointmentNo": appoNo, "MobileNo": mobileNo, "UserID": 102, "LanguageID": 1};
    dynamic localRes;
    await baseAppClient.post(AUTO_GENERATE_INVOICE_TAMARA, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);

    return Future.value(localRes);
  }

  Future<Map> autoGenerateInvoiceERClinic(int? projectID, int? paymentMethod, String? paymentReferenceNo, num? amount, String? cardType, String? cardNumber, String? orderID, String? rrn, bool isAdvanceAvailable) async {
    Map<String, dynamic> request;
    request = {
      "ProjectID": projectID,
      "ClinicID": "10",
      // "PaymentMethod": paymentMethod,
      "PaymentMethod": "VISA",
      "PaymentReferenceNo": paymentReferenceNo,
      "PaymentAmount": amount,
      "CardType": cardType,
      "CardNumber": cardNumber,
      "OrderId": orderID,
      "MemberID": 102,
      "RRN": rrn,
      "IsAdvanceAvailable": isAdvanceAvailable
    };
    dynamic localRes;
    await baseAppClient.post(AUTO_GENERATE_INVOICE_ER, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);

    return Future.value(localRes);
  }

  Future<Map> checkPatientNphiesEligibility(int projectID) async {
    Map<String, dynamic> request;
    request = {"ProjectID": projectID, "LanguageID": 1};
    dynamic localRes;
    await baseAppClient.post(CHECK_PATIENT_NPHIES_ELIGIBILITY, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);

    return Future.value(localRes);
  }

  Future<Map> convertPatientToCash(int projectID) async {
    Map<String, dynamic> request;
    request = {"ProjectID": projectID, "LanguageID": 1};
    dynamic localRes;
    await baseAppClient.post(CONVERT_PATIENT_TO_CASH, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);

    return Future.value(localRes);
  }

  Future<Map> getAncillaryOrders() async {
    Map<String, dynamic> body = Map();

    hasError = false;
    dynamic localRes;
    await baseAppClient.post(GET_ANCILLARY_ORDERS, onSuccess: (dynamic response, int statusCode) {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);

    return Future.value(localRes);
  }

  Future<Map> getPayfortSDKTokenForPayment(String deviceID, String signatureValue, {bool isTest = true}) async {
    Map<String, dynamic> request;
    request = {"service_command": "SDK_TOKEN", "access_code": "BsM6He4FMBaZ86W64kjZ", "merchant_identifier": "ipxnRXXq", "language": "en", "device_id": deviceID, "signature": signatureValue};
    dynamic localRes;
    await baseAppClient.post(isTest ? PAYFORT_TEST_URL : PAYFORT_PROD_URL, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request, isExternal: true, isAllowAny: true);

    return Future.value(localRes);
  }

  Future<Map> logDoctorFreeSlots(int docID, int clinicID, int projectID, List<dynamic> selectedfreeSlots, dynamic appoNumber, BuildContext context, [ProjectViewModel? projectViewModel]) async {
    Map<String, dynamic> requestFreeSlots;
    Map<String, dynamic> request;

    Request req = appGlobal.getPublicRequest();
    requestFreeSlots = {
      "DoctorID": docID,
      "IsBookingForLiveCare": 0,
      "ClinicID": clinicID,
      "ProjectID": projectID,
      "OriginalClinicID": clinicID,
      "days": 0,
      "isReschadual": false,
      "VersionID": req.VersionID,
      "Channel": 3,
      "IPAdress": "10.20.10.20",
      "generalid": "Cs2020@2016\$2958",
      "PatientOutSA": authProvider.isLogin ? authUser.outSA : 0,
      "SessionID": null,
      "isDentalAllowedBackend": false,
      "LanguageID": 1,
      "DeviceTypeID": 1
    };

    request = {"ClinicID": clinicID, "ProjectID": projectID, "AppointmentNo": appoNumber, "DoctorFreeSlotRequest": requestFreeSlots, "DoctorFreeSlotResponse": selectedfreeSlots, "Value1": docID};
    dynamic localRes;
    await baseAppClient.post(INSERT_FREE_SLOTS_LOGS, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);

    return Future.value(localRes);
  }
}
