import 'dart:ui';

import 'package:hmg_qline/constants/app_constants.dart';
import 'package:hmg_qline/models/kiosk_language_config_model.dart';
import 'package:hmg_qline/models/kiosk_queue_model.dart';
import 'package:hmg_qline/utilities/enums.dart';
import 'package:hmg_qline/utilities/extensions.dart';

class GlobalConfigurationsModel {
  int? id;
  int? configType;
  String? description;
  int? counterStart;
  int? counterEnd;
  int concurrentCallDelaySec = 1;
  int? voiceType;
  String? voiceTypeText;
  LanguageEnum screenLanguageEnum = LanguageEnum.english;
  String? screenLanguageText;
  TextDirection textDirection = TextDirection.ltr;
  LanguageEnum voiceLanguageEnum = LanguageEnum.english;
  String? voiceLanguageText;
  int screenMaxDisplayPatients = 16;
  bool? isNotiReq;
  int? prioritySMS;
  int? priorityWhatsApp;
  int? priorityEmail;
  String ticketNoText = "Ticket Number";
  String postVoiceText = "Please Visit Counter";

  int? roomNo;
  bool? isRoomNoRequired;
  String? roomTextEng;
  String? counterTextEng;
  String? queueNoTextEng;
  String? callForTextEng;
  String? roomTextArb;
  String? counterTextArb;
  String? queueNoTextArb;
  String? callForTextArb;
  String? currentServeTextEng;
  String? currentServeTextArb;
  String maxText = "";
  String minText = "";
  String nextPrayerTextEng = "Next Prayer";
  String nextPrayerTextArb = "الصلا�� القادمة";
  String weatherText = "Weather";
  String? fajarTextEng;
  String? dhuhrTextEng;
  String? asarTextEng;
  String? maghribTextEng;
  String? ishaTextEng;
  String? fajarTextArb;
  String? dhuhrTextArb;
  String? asarTextArb;
  String? maghribTextArb;
  String? ishaTextArb;
  bool? isActive;
  int? createdBy;
  String? createdOn;
  dynamic editedBy;
  dynamic editedOn;
  bool isToneReq = false;
  bool isVoiceReq = false;
  ScreenOrientationEnum orientationTypeEnum = ScreenOrientationEnum.portraitUp;
  bool? isTurnOn;
  int? waitingAreaType;
  int? gender;
  bool isWeatherReq = false;
  bool isPrayerTimeReq = false;
  bool isRssFeedReq = false;
  bool globalClinicPrefixReq = false;
  bool clinicPrefixReq = true;
  QTypeEnum qTypeEnum = QTypeEnum.appointment;
  ScreenTypeEnum screenTypeEnum = ScreenTypeEnum.waitingAreaScreen;
  int? projectID;
  double? projectLatitude;
  double? projectLongitude;
  int? cityKey;
  List<KioskQueueModel>? kioskQueueList;
  List<KioskLanguageConfigModel>? kioskLanguageConfigList;

  // Indicates whether the screen belongs to Takhasusi main (based on its IP)
  bool isFromTakhasusiMain = false;

  String vitalSignTextEng = "Vital Sign";
  String doctorTextEng = "Doctor";
  String procedureTextEng = "Procedure";
  String vaccinationTextEng = "Vaccination";
  String nebulizationTextEng = "Nebulization";
  String callForVitalSignTextEng = "Call for Vital Sign";
  String callForDoctorTextEng = "Call for Doctor";
  String callForProcedureTextEng = "Call for Procedure";
  String callForVaccinationTextEng = "Call for Vaccination";
  String callForNebulizationTextEng = "Call for Nebulization";

  String vitalSignTextArb = "العلامات الحيوية";
  String doctorTextArb = "الطبيب";
  String procedureTextArb = "الإجراء";
  String vaccinationTextArb = "التطعيم";
  String nebulizationTextArb = "البخاخة";
  String callForVitalSignTextArb = "الرجاء التوجّه إلى غرفة العلامات الحيوية";
  String callForDoctorTextArb = "الرجاء التوجّه إلى غرفة الطبيب";
  String callForProcedureTextArb = "الرجاء التوجّه إلى غرفة الإجراء";
  String callForVaccinationTextArb = "الرجاء التوجّه إلى غرفة التطعيم";
  String callForNebulizationTextArb = "الرجاء التوجّه إلى غرفة البخاخة";

  GlobalConfigurationsModel({
    this.id,
    this.configType,
    this.description,
    this.counterStart,
    this.counterEnd,
    this.concurrentCallDelaySec = 1,
    this.voiceType,
    this.voiceTypeText,
    this.screenLanguageEnum = LanguageEnum.english,
    this.screenLanguageText,
    this.textDirection = TextDirection.ltr,
    this.voiceLanguageEnum = LanguageEnum.english,
    this.voiceLanguageText,
    this.screenMaxDisplayPatients = 16,
    this.isNotiReq,
    this.prioritySMS,
    this.priorityWhatsApp,
    this.priorityEmail,
    this.ticketNoText = "Ticket Number",
    this.postVoiceText = "Please Visit Counter",
    this.roomTextEng,
    this.roomNo,
    this.isRoomNoRequired = true,
    this.counterTextEng,
    this.queueNoTextEng,
    this.callForTextEng,
    this.counterTextArb,
    this.queueNoTextArb,
    this.callForTextArb,
    this.currentServeTextEng,
    this.currentServeTextArb,
    this.maxText = "",
    this.minText = "",
    this.nextPrayerTextEng = "Next Prayer",
    this.nextPrayerTextArb = "الصلاة القادمة",
    this.weatherText = "Weather",
    this.fajarTextEng,
    this.dhuhrTextEng,
    this.asarTextEng,
    this.maghribTextEng,
    this.ishaTextEng,
    this.fajarTextArb,
    this.dhuhrTextArb,
    this.asarTextArb,
    this.maghribTextArb,
    this.ishaTextArb,
    this.isActive,
    this.createdBy,
    this.createdOn,
    this.editedBy,
    this.editedOn,
    this.isToneReq = false,
    this.isVoiceReq = false,
    this.orientationTypeEnum = ScreenOrientationEnum.portraitUp,
    this.isTurnOn,
    this.waitingAreaType,
    this.gender,
    this.isWeatherReq = false,
    this.isPrayerTimeReq = false,
    this.isRssFeedReq = false,
    this.globalClinicPrefixReq = false,
    this.clinicPrefixReq = true,
    this.qTypeEnum = QTypeEnum.appointment,
    this.screenTypeEnum = ScreenTypeEnum.waitingAreaScreen,
    this.projectID,
    this.projectLatitude,
    this.projectLongitude,
    this.cityKey,
    this.kioskQueueList,
    this.kioskLanguageConfigList,
    this.isFromTakhasusiMain = false,
    this.vitalSignTextEng = "Vital Sign",
    this.doctorTextEng = "Doctor",
    this.procedureTextEng = "Procedure",
    this.vaccinationTextEng = "Vaccination",
    this.nebulizationTextEng = "Nebulization",
    this.callForVitalSignTextEng = "Call for Vital Sign",
    this.callForDoctorTextEng = "Call for Doctor",
    this.callForProcedureTextEng = "Call for Procedure",
    this.callForVaccinationTextEng = "Call for Vaccination",
    this.callForNebulizationTextEng = "Call for Nebulization",
    this.vitalSignTextArb = "العلامات الحيوية",
    this.doctorTextArb = "الطبيب",
    this.procedureTextArb = "الإجراء",
    this.vaccinationTextArb = "التطعيم",
    this.nebulizationTextArb = "البخاخة",
    this.callForVitalSignTextArb = "استدعاء للعلامات الحيوية",
    this.callForDoctorTextArb = "الرجاء التوجّه إلى غرفة الطبيب",
    this.callForProcedureTextArb = "الرجاء التوجّه إلى غرفة الإجراء",
    this.callForVaccinationTextArb = "الرجاء التوجّه إلى غرفة التطعيم",
    this.callForNebulizationTextArb = "الرجاء التوجّه إلى غرفة البخاخة",
  });

  GlobalConfigurationsModel.fromJson({required Map<String, dynamic> json, int qType = 1, int screenType = 1}) {
    id = json['id'];
    configType = json['configType'];
    description = json['description'];
    counterStart = json['counterStart'];
    counterEnd = json['counterEnd'];
    concurrentCallDelaySec = json['concurrentCallDelaySec'] ?? 1;
    voiceType = json['voiceType'];
    voiceTypeText = json['voiceTypeText'];
    screenLanguageEnum = (json['screenLanguage'] as int).toLanguageEnum();
    screenLanguageText = json['screenLanguageText'];
    // textDirection = json['textDirection'] == 2 ? TextDirection.rtl : TextDirection.ltr;
    textDirection = TextDirection.rtl;
    screenMaxDisplayPatients = json['screenMaxDisplayPatients'] ?? 16;
    // screenMaxDisplayPatients = 15;
    voiceLanguageEnum = (json['voiceLanguage'] as int).toLanguageEnum();
    voiceLanguageText = json['voiceLanguageText'];
    isNotiReq = json['isNotiReq'];
    prioritySMS = json['prioritySMS'];
    priorityWhatsApp = json['priorityWhatsApp'];
    priorityEmail = json['priorityEmail'];
    ticketNoText = json['ticketNoText'] ?? "Ticket Number";
    postVoiceText = json['pleaseVisitCounterText'] ?? "Please Visit Counter";
    roomNo = json['roomNo'];
    isRoomNoRequired = json['isRoomNoReq'] ?? true;
    queueNoTextEng = json['queueNoText'];
    callForTextEng = json['callForText'];
    counterTextEng = json['counterText'];
    roomTextEng = json['roomText'];
    queueNoTextArb = json['queueNoTextAr'] ?? "الرقم";
    callForTextArb = json['callForTextAr'] ?? "التوجه إلى";
    counterTextArb = json['counterTextAr'] ?? "";
    roomTextArb = json['roomTextAr'] ?? "الغرفة";
    currentServeTextEng = json['currentServeText'];
    currentServeTextArb = json['currentServeTextAr'] ?? "يتم خدمة";
    maxText = json['maxText'] ?? "";
    minText = json['minText'] ?? "";
    nextPrayerTextEng = json['nextPrayerText'] ?? "Next Prayer";
    nextPrayerTextArb = json['nextPrayerTextArb'] ?? "الصلاة القادمة";
    weatherText = json['weatherText'] ?? "Weather";
    fajarTextEng = json['fajarText'];
    dhuhrTextEng = json['dhuhrText'];
    asarTextEng = json['asarText'];
    maghribTextEng = json['maghribText'];
    ishaTextEng = json['ishaText'];
    fajarTextArb = json['fajarTextAr'] ?? AppStrings.prayersArray[0];
    dhuhrTextArb = json['dhuhrTextAr'] ?? AppStrings.prayersArray[1];
    asarTextArb = json['asarTextAr'] ?? AppStrings.prayersArray[2];
    maghribTextArb = json['maghribTextAr'] ?? AppStrings.prayersArray[3];
    ishaTextArb = json['ishaTextAr'] ?? AppStrings.prayersArray[4];
    isActive = json['isActive'];
    createdBy = json['createdBy'];
    createdOn = json['createdOn'];
    editedBy = json['editedBy'];
    editedOn = json['editedOn'];
    isToneReq = json['isToneReq'] ?? false;
    isVoiceReq = json['isVoiceReq'] ?? false;
    orientationTypeEnum = ((json['orientationType'] ?? 1) as int).toScreenOrientationEnum();
    isTurnOn = json['isTurnOn'];
    waitingAreaType = json['waitingAreaType'];
    gender = json['gender'];
    isWeatherReq = json['isWeatherReq'] ?? false;
    isPrayerTimeReq = json['isPrayerTimeReq'] ?? false;
    isRssFeedReq = json['isRssFeedReq'] ?? false;
    globalClinicPrefixReq = json['globalClinicPrefixReq'] ?? false;
    clinicPrefixReq = json['clinicPrefixReq'] ?? true;
    qTypeEnum = ((json['qType'] ?? qType) as int).toQTypeEnum();
    screenTypeEnum = ((json['screenType'] ?? screenType) as int).toScreenTypeEnum();
    projectID = json['projectID'];
    projectLatitude = json['projectLatitude'] == 0 ? 0.0 : json['projectLatitude'];
    projectLongitude = json['projectLongitude'] == 0 ? 0.0 : json['projectLongitude'];
    cityKey = json['cityKey'] ?? 0;
    if (json['kioskQueue'] != null) {
      kioskQueueList = List<KioskQueueModel>.from(json['kioskQueue'].map((kioskQueueJson) => KioskQueueModel.fromJson(kioskQueueJson)));
    } else {
      kioskQueueList = [];
    }
    if (json['kioskConfig'] != null) {
      kioskLanguageConfigList =
          List<KioskLanguageConfigModel>.from(json['kioskConfig'].map((kioskQueueJson) => KioskLanguageConfigModel.fromJson(kioskQueueJson)));
    } else {
      kioskLanguageConfigList = [];
    }
    // Default to false; actual value (based on device IP) is set in ViewModel after loading config
    isFromTakhasusiMain = false;
    vitalSignTextEng = json['vitalSignText'] ?? "Vital Sign";
    doctorTextEng = json['doctorText'] ?? "Doctor";
    procedureTextEng = json['procedureText'] ?? "Procedure";
    vaccinationTextEng = json['vaccinationText'] ?? "Vaccination";
    nebulizationTextEng = json['nebulizationText'] ?? "Nebulization";
    callForVitalSignTextEng = json['callForVitalSignText'] ?? "Call for Vital Sign";
    callForDoctorTextEng = json['callForDoctorText'] ?? "Call for Doctor";
    callForProcedureTextEng = json['callForProcedureText'] ?? "Call for Procedure";
    callForVaccinationTextEng = json['callForVaccinationText'] ?? "Call for Vaccination";
    callForNebulizationTextEng = json['callForNebulizationText'] ?? "Call for Nebulization";

    vitalSignTextArb = json['vitalSignTextAr'] ?? "غرفة العلامات الحيوية";
    doctorTextArb = json['doctorTextAr'] ?? " غرفة الطبيب";
    procedureTextArb = json['procedureTextAr'] ?? "غرفة الإجراء";
    vaccinationTextArb = json['vaccinationTextAr'] ?? "غرفة التطعيم";
    nebulizationTextArb = json['nebulizationTextAr'] ?? "غرفة البخاخة";
    callForVitalSignTextArb = json['callForVitalSignTextAr'] ?? " غرفة استدعاء للعلامات الحيوية";
    callForDoctorTextArb = json['callForDoctorTextAr'] ?? "الرجاء التوجّه إلى غرفة الطبيب";
    callForProcedureTextArb = json['callForProcedureTextAr'] ?? "الرجاء التوجّه إلى غرفة الإجراء";
    callForVaccinationTextArb = json['callForVaccinationTextAr'] ?? "الرجاء لتوجّه إلى غرفة التطعيم";
    callForNebulizationTextArb = json['callForNebulizationTextAr'] ?? "الرجاء التوجّه إلى غرفة البخاخة";
  }

  @override
  String toString() {
    return 'GlobalConfigurationsModel{id: $id, isFromTakhasusiMain: $isFromTakhasusiMain, configType: $configType, description: $description, counterStart: $counterStart, counterEnd: $counterEnd, concurrentCallDelaySec: $concurrentCallDelaySec, voiceType: $voiceType, voiceTypeText: $voiceTypeText, screenLanguageEnum: $screenLanguageEnum, screenLanguageText: $screenLanguageText, textDirection: $textDirection, voiceLanguageEnum: $voiceLanguageEnum, voiceLanguageText: $voiceLanguageText, screenMaxDisplayPatients: $screenMaxDisplayPatients, isNotiReq: $isNotiReq, prioritySMS: $prioritySMS, priorityWhatsApp: $priorityWhatsApp, priorityEmail: $priorityEmail, ticketNoText: $ticketNoText, postVoiceText: $postVoiceText, roomText: $roomTextEng, roomNo: $roomNo, isRoomNoRequired: $isRoomNoRequired, counterText: $counterTextEng, queueNoText: $queueNoTextEng, callForText: $callForTextEng, currentServeTextArb: $currentServeTextArb,, currentServeTextEng: $currentServeTextEng, maxText: $maxText, minText: $minText, nextPrayerTextEng: $nextPrayerTextEng, nextPrayerTextArb: $nextPrayerTextArb, weatherText: $weatherText, fajarText: $fajarTextEng, dhuhrText: $dhuhrTextEng, asarText: $asarTextEng, maghribText: $maghribTextEng, ishaText: $ishaTextEng, isActive: $isActive, createdBy: $createdBy, createdOn: $createdOn, editedBy: $editedBy, editedOn: $editedOn, isToneReq: $isToneReq, isVoiceReq: $isVoiceReq, orientationTypeEnum: $orientationTypeEnum, isTurnOn: $isTurnOn, waitingAreaType: $waitingAreaType, gender: $gender, isWeatherReq: $isWeatherReq, isPrayerTimeReq: $isPrayerTimeReq, isRssFeedReq: $isRssFeedReq, globalClinicPrefixReq: $globalClinicPrefixReq, clinicPrefixReq: $clinicPrefixReq, qTypeEnum: $qTypeEnum, screenTypeEnum: $screenTypeEnum, projectID: $projectID, projectLatitude: $projectLatitude, projectLongitude: $projectLongitude, cityKey: $cityKey, kioskQueueList: $kioskQueueList, kioskLanguageConfigList: $kioskLanguageConfigList, vitalSignText: $vitalSignTextEng, doctorText: $doctorTextEng, procedureText: $procedureTextEng, vaccinationText: $vaccinationTextEng, nebulizationText: $nebulizationTextEng, callForVitalSignText: $callForVitalSignTextEng, callForDoctorText: $callForDoctorTextEng, callForProcedureText: $callForProcedureTextEng, callForVaccinationText: $callForVaccinationTextEng, callForNebulizationText: $callForNebulizationTextEng, vitalSignTextArb: $vitalSignTextArb, doctorTextArb: $doctorTextArb, procedureTextArb: $procedureTextArb, vaccinationTextArb: $vaccinationTextArb, nebulizationTextArb: $nebulizationTextArb, callForVitalSignTextArb: $callForVitalSignTextArb, callForDoctorTextArb: $callForDoctorTextArb, callForProcedureTextArb: $callForProcedureTextArb, callForVaccinationTextArb: $callForVaccinationTextArb, callForNebulizationTextArb: $callForNebulizationTextArb}';
  }
}
