import 'package:flyinsono/architecture/config/model.dart';
import 'package:flyinsono/architecture/states/states.dart';
import 'package:flyinsono/architecture/values/features.dart';
import 'package:flyinsono/global.dart';
import 'package:flyinsono/pages/setting/server_setting/state.dart';
import 'package:flyinsono/utils/export_status_type.dart';
import 'package:flyinsono/views/desktop/real_time_consultation/widgets/simple_Info.dart';
import 'package:get/get.dart';
import 'package:fis_i18n/i18n.dart';

class UserSettingServerOptionModel {
  late final String port;
  late final String host;
  late final String protocol;
  late final String name;
  late final String fullAddress;
  final bool isDefault;

  UserSettingServerOptionModel(String fullAddress, [this.isDefault = false]) {
    if (isDefault) {
      this.fullAddress = DefaultServerName;
    } else {
      this.fullAddress = fullAddress;
    }
    final uri = Uri.parse(fullAddress);
    port = uri.port.toString();
    host = uri.host;
    protocol = uri.scheme;
    if (isDefault) {
      name = i18nBook.common.appName.t;
    } else {
      name = "$host:$port";
    }
  }
}

class UserSettingState {
  final RxBool _isUseSecondWindow = RxBool(false);
  final RxBool _isAutoStartUp = RxBool(false);
  final RxBool _isAutoPopupReportTag = RxBool(false);
  final RxInt _settingTabIndex = RxInt(0);
  final Rx<String> _currLanguage = Rx<String>('zh');
  final Rx<List<ServerOptionModel>> _serverList = Rx(<ServerOptionModel>[]);
  final Rx<String> _currServer =
      Rx<String>(Global.config.data.flyinsonoServers.first);
  final RxInt _settingVersionUpdateMode = RxInt(0);
  final Rx<ExportStatusType?> _exportState = Rx(null);
  final RxList<String> _myRoleType = RxList([]);
  final RxBool _secondWindowOpening = RxBool(false);
  final Rx<String> _myAssistantName = Rx('');
  final Rx<String> _vBoxSettingPageUrl = Rx('');
  final Rx<String> _assistantPhysicianName = Rx('');

  ///我的助理(已绑定的)
  String bindingAssistant = "";

  ///我的助理医师(已绑定的)
  String bindingAssistantPhysician = "";

  ///当前机构的专家助理
  List<SimpleInfoItem> assistantList = [];

  ///当前机构的认证医师
  List<SimpleInfoItem> certifiedPhysicianList = [];

  /// vbox访问地址
  set vBoxSettingPageUrl(String value) => _vBoxSettingPageUrl.value = value;
  String get vBoxSettingPageUrl => _vBoxSettingPageUrl.value;

  ///我的用户角色类型
  List<String> get myRoleTypes => _myRoleType;
  set myRoleTypes(List<String> v) => _myRoleType.value = v;

  String get currLanguage => _currLanguage.value;

  /// 当前语言
  set currLanguage(String value) => _currLanguage.value = value;
  String get currServer => _currServer.value;

  /// 当前服务器
  set currServer(String value) => _currServer.value = value;
  ExportStatusType? get exportState => _exportState.value;

  /// 当前日志导出状态
  set exportState(ExportStatusType? value) => _exportState.value = value;
  bool get isAutoPopupReportTag => _isAutoPopupReportTag.value;

  /// 是否编写完报告自动弹窗标签
  set isAutoPopupReportTag(bool value) => _isAutoPopupReportTag.value = value;
  bool get isAutoStartUp => _isAutoStartUp.value;

  /// 是否开机自启动
  set isAutoStartUp(bool value) => _isAutoStartUp.value = value;
  bool get isUseSecondWindow => _isUseSecondWindow.value;

  /// 是否是第二窗口打开
  set isUseSecondWindow(bool value) => _isUseSecondWindow.value = value;
  List<ServerOptionModel> get serverList => _serverList.value;

  /// 服务列表
  set serverList(List<ServerOptionModel> value) => _serverList.value = value;

  int get settingTabIndex => _settingTabIndex.value;

  /// 设置页面下标
  set settingTabIndex(int value) => _settingTabIndex.value = value;

  int get settingVersionUpdateMode => _settingVersionUpdateMode.value;

  /// 当前选择的更新模式
  set settingVersionUpdateMode(int value) =>
      _settingVersionUpdateMode.value = value;

  /// 第二窗口开启中
  set secondWindowOpening(bool value) => _secondWindowOpening.value = value;
  bool get secondWindowOpening => _secondWindowOpening.value;

  /// 我的助理
  set myAssistantName(String value) => _myAssistantName.value = value;
  String get myAssistantName => _myAssistantName.value;

  /// 助理医师
  set assistantPhysicianName(String value) =>
      _assistantPhysicianName.value = value;
  String get assistantPhysicianName => _assistantPhysicianName.value;

  /// 个性化设置的权限
  bool get isPersonalSettingAuth =>
      Store.user.hasFeature(FeatureKeys.PersonalSetting);
}
