import 'dart:io';

import 'package:easy_localization/easy_localization.dart';
import 'package:hmg_patient_app_new/core/common_models/privilege/HMCProjectListModel.dart';
import 'package:hmg_patient_app_new/core/common_models/privilege/PrivilegeModel.dart';
import 'package:hmg_patient_app_new/core/common_models/privilege/ProjectDetailListModel.dart';
import 'package:hmg_patient_app_new/core/common_models/privilege/VidaPlusProjectListModel.dart';
import 'package:hmg_patient_app_new/features/authentication/models/request_models/send_activation_request_model.dart';
import 'package:hmg_patient_app_new/features/authentication/models/resp_models/authenticated_user_resp_model.dart';
import 'package:hmg_patient_app_new/features/authentication/models/resp_models/check_user_staus_nhic_response_model.dart';
import 'package:hmg_patient_app_new/features/authentication/models/resp_models/select_device_by_imei.dart';
import 'package:hmg_patient_app_new/services/navigation_service.dart';

import '../features/authentication/models/request_models/registration_payload_model.dart';

class AppState {
  NavigationService navigationService;

  AppState({required this.navigationService});

  double userLat = 0.0;

  set setUserLat(v) => userLat = v;

  double userLong = 0.0;

  set setUserLong(v) => userLong = v;

  bool isArabic() => EasyLocalization.of(navigationService.navigatorKey.currentContext!)?.locale.languageCode == "ar";

  int getLanguageID() => EasyLocalization.of(navigationService.navigatorKey.currentContext!)?.locale.languageCode == "ar" ? 1 : 2;

  int getDeviceTypeID() => Platform.isIOS ? 1 : 2;

  String? getLanguageCode() => EasyLocalization.of(navigationService.navigatorKey.currentContext!)?.locale.languageCode;

  AuthenticatedUser? _authenticatedRootUser;
  AuthenticatedUser? _authenticatedChildUser;

  int? _superUserID;
  bool isChildLoggedIn = false;

  void setAuthenticatedUser(AuthenticatedUser? authenticatedUser, {bool isFamily = false}) {
    if (isFamily) {
      _authenticatedChildUser = authenticatedUser;
    } else {
      setIsAuthenticated = true;
      _authenticatedRootUser = authenticatedUser;
    }
  }

  AuthenticatedUser? getAuthenticatedUser({bool isFamily = false}) {
    if (isFamily) {
      return _authenticatedChildUser;
    } else {
      return _authenticatedRootUser;
    }
  }

  int? get getSuperUserID => _superUserID;

  bool get getIsChildLoggedIn => isChildLoggedIn;

  set setSuperUserID(int? value) => _superUserID = value;

  set setIsChildLoggedIn(bool value) => isChildLoggedIn = value;

  String _userBloodGroup = "";

  String get getUserBloodGroup => _userBloodGroup;

  set setUserBloodGroup(String value) => _userBloodGroup = value;

  SelectDeviceByImeiRespModelElement? _selectDeviceByImeiRespModelElement;

  void setSelectDeviceByImeiRespModelElement(SelectDeviceByImeiRespModelElement? value) {
    _selectDeviceByImeiRespModelElement = value;
  }

  SelectDeviceByImeiRespModelElement? get getSelectDeviceByImeiRespModelElement => _selectDeviceByImeiRespModelElement;

  // String appLoginTokenID = "";
  //
  // set setAppLoginTokenID(v) => appLoginTokenID = v;

  String deviceToken = "";

  set setDeviceToken(v) => deviceToken = v;

  String voipToken = "";

  set setVoipToken(v) => voipToken = v;

  String appAuthToken = "";

  set setAppAuthToken(v) => appAuthToken = v;

  String sessionId = "";

  set setSessionId(v) => sessionId = v;

  bool isAuthenticated = false;

  set setIsAuthenticated(v) => isAuthenticated = v;

  String deviceTypeID = "";

  set setDeviceTypeID(v) => deviceTypeID = v;

  String _familyFileTokenID = "";

  String get getFamilyFileTokenID => _familyFileTokenID;

  set setFamilyFileTokenID(String value) {
    _familyFileTokenID = value;
  }

  List<VidaPlusProjectListModel> vidaPlusProjectList = [];
  List<ListPrivilege> privilegeModelList = [];
  List<HMCProjectListModel> hMCProjectListModel = [];
  List<ProjectDetailListModel> projectDetailListModel = [];

  setVidaPlusProjectList(List<VidaPlusProjectListModel> vidaPlusProjectListModelInput) {
    vidaPlusProjectList = vidaPlusProjectListModelInput;
  }

  setPrivilegeModelList(List<ListPrivilege> privilegeModelListInput) {
    privilegeModelList = privilegeModelListInput;
  }

  setHMCProjectList(List<HMCProjectListModel> hMCProjectListModelInput) {
    hMCProjectListModel = hMCProjectListModelInput;
  }

  setProjectsDetailList(List<ProjectDetailListModel> projectDetailListModelInput) {
    projectDetailListModel = projectDetailListModelInput;
  }

  CheckUserStatusResponseNHIC? _nHICUserData;

  CheckUserStatusResponseNHIC get getNHICUserData => _nHICUserData!;

  set setNHICUserData(CheckUserStatusResponseNHIC value) {
    _nHICUserData = value;
  }

  RegistrationDataModelPayload? _userRegistrationPayload;

  RegistrationDataModelPayload get getUserRegistrationPayload => _userRegistrationPayload ?? RegistrationDataModelPayload();

  set setUserRegistrationPayload(RegistrationDataModelPayload value) {
    _userRegistrationPayload = value;
  }

  ///this will be called if there is any problem in getting the user location
  void resetLocation() {
    userLong = 0.0;
    userLong = 0.0;
  }
}
