import 'package:fis_jsonrpc/services/index.dart';
import 'package:flyinsono/pages/organization/org_info/state.dart';
import 'package:flyinsono/pages/remedical/consultation/widgets/muti_select.dart';
import 'package:get/get.dart';
import 'package:fis_ui/index.dart';
import 'entrtys/device_info.dart';

class UserDeviceState {
  final RxInt _pageIndex = RxInt(1);
  final RxInt _selectIndex = RxInt(0);
  final Rx<String> _queryString = ''.obs;
  final RxList<DeviceExtendInfoDTO> _dataList = RxList<DeviceExtendInfoDTO>();
  final RxInt _selectTerminalCardIndex = RxInt(0);
  final _selectedTerminal = DeviceExtendInfoDTO().obs;
  final Rx<String> _deviceTypeCode = Rx('');
  final Rx<String> _deviceModelCode = Rx('');
  final Rx<bool> _isOrgDevice = Rx(false);
  final Rx<List<FSelectModel>> _deviceTypes = Rx(<FSelectModel>[]);
  final Rx<List<FSelectModel>> _deviceModels = Rx(<FSelectModel>[]);
  final Rx<OnlineStatus> _deviceStatus = Rx(OnlineStatus.All);
  final Rx<bool> _checked = Rx(false);
  // late final Rx<Map<String, dynamic>> device = Rx(<String, dynamic>{});
  final Rx<DeviceInfo> _deviceInfo = Rx(DeviceInfo());
  final Rx<List<OrgModel>> _depOptions = Rx(<OrgModel>[]);
  final Rx<List<ShareDeviceUserDTO>> _tableDataSource =
      Rx(<ShareDeviceUserDTO>[]);
  final Rx<bool> _isCanShare = Rx(true);
  final Rx<List<String>> _selectList = Rx(<String>[]);
  final Rx<List<String>> _shareUserSelectList = Rx(<String>[]);
  final Rx<List<UserExtendDTO>> _users = Rx(<UserExtendDTO>[]);
  final Rx<List<UserExtendDTO>> _selectedUsers = Rx(<UserExtendDTO>[]);
  final Rx<List<OrganizationDTO>> _deps = Rx(<OrganizationDTO>[]);
  final Rx<bool> _batchOperation = Rx(false);
  final RxString _selectedECDevice = RxString('');
  final Rx<String> _deviceName = Rx('');
  final Rx<String> _deviceDescription = Rx('');
  final Rx<String> _deviceImage = Rx('');
  final Rx<List<DiagnosisModuleDTO>> _diagnosisModule =
      Rx(<DiagnosisModuleDTO>[]);
  final Rx<List<FMutiSelectModel>> _organizationLocatedList =
      Rx(<FMutiSelectModel>[]);
  final Rx<List<String>> _selectedOrganizationLocated = Rx(<String>[]);

  ///急诊设备Code(emergency consultacion device)
  String get selectedECDevice => _selectedECDevice.value;
  set selectedECDevice(String v) => _selectedECDevice.value = v;

  ///所有组织下用户
  List<UserExtendDTO> get selectedUsers => _selectedUsers.value;
  set selectedUsers(List<UserExtendDTO> v) => _selectedUsers(v);

  ///设备信息
  DeviceInfo get deviceInfo => _deviceInfo.value;
  set deviceInfo(DeviceInfo d) => _deviceInfo.value = d;

  ///所有组织下用户
  List<UserExtendDTO> get users => _users.value;
  set users(List<UserExtendDTO> v) => _users(v);

  List<UserExtendDTO> allUsers = [];

  ///所有部门
  List<OrganizationDTO> get deps => _deps.value;
  set deps(List<OrganizationDTO> values) => _deps(values);

  ///用户设备or组织设备
  bool get isOrgDevice => _isOrgDevice.value;
  set isOrgDevice(bool v) => _isOrgDevice.value = v;

  ///所选设备类型编码
  String get deviceType => _deviceTypeCode.value;
  set deviceType(String v) => _deviceTypeCode.value = v;

  ///在线状态
  OnlineStatus get deviceStatus => _deviceStatus.value;
  set deviceStatus(OnlineStatus value) => _deviceStatus.value = value;

  ///所选设备模式编码
  String get deviceModel => _deviceModelCode.value;
  set deviceModel(String v) => _deviceModelCode.value = v;

  /// 设备类型列表
  List<FSelectModel> get deviceTypes => _deviceTypes.value;
  set deviceTypes(List<FSelectModel> v) => _deviceTypes(v);

  /// 设备类型列表
  List<FSelectModel> get deviceModels => _deviceModels.value;
  set deviceModels(List<FSelectModel> v) => _deviceModels(v);

  /// 病人详情、检查报告、检查记录、扫查图像 tab跳转
  set selectIndex(value) => _selectIndex.value = value;
  get selectIndex => _selectIndex.value;

  ///当前页码
  int get pageIndex => _pageIndex.value;
  set pageIndex(int v) => _pageIndex.value = v;

  /// 搜索文本
  String get queryString => _queryString.value;
  set queryString(String v) => _queryString.value = v;

  /// 数据列表
  List<DeviceExtendInfoDTO> get terminals => _dataList;
  set terminals(List<DeviceExtendInfoDTO> v) => _dataList(v);

  String get deviceName => _deviceName.value;
  set deviceName(String v) => _deviceName.value = v;

  String get deviceDescription => _deviceDescription.value;
  set deviceDescription(String val) => _deviceDescription.value = val;

  String get deviceImage => _deviceImage.value;
  set deviceImage(String v) => _deviceImage.value = v;

  ///当前所选超声机
  DeviceExtendInfoDTO get selectedTerminal => _selectedTerminal.value;
  set selectedTerminal(DeviceExtendInfoDTO val) {
    _selectedTerminal.value = val;
    deviceName = val.displayName ?? '';
    deviceImage = val.headPicUrl ?? '';
    deviceDescription = val.description ?? '';
  }

  /// 超声机Card
  set selectTerminalCardIndex(int value) =>
      _selectTerminalCardIndex.value = value;
  int get selectTerminalCardIndex => _selectTerminalCardIndex.value;

  /// 是否一键分享
  bool get checked => _checked.value;
  set checked(bool v) => _checked.value = v;

  /// 部门选项集合
  set depOptions(List<OrgModel> value) => _depOptions(value);
  List<OrgModel> get depOptions => _depOptions.value;

  /// 表格数据 [设备绑定的所有人]
  List<ShareDeviceUserDTO> get tableDataSource => _tableDataSource.value;
  set tableDataSource(List<ShareDeviceUserDTO> value) =>
      _tableDataSource(value);

  /// 是否绑定过
  bool get isCanShare => _isCanShare.value;
  set isCanShare(bool v) => _isCanShare.value = v;

  /// 数据列表
  set selectList(List<String> value) => _selectList(value);
  List<String> get selectList => _selectList.value;

  /// 手机端是否是批量删除用户
  bool get batchOperation => _batchOperation.value;
  set batchOperation(bool val) => _batchOperation.value = val;

  /// 分享的设备 List
  set shareUserSelectList(List<String> value) => _shareUserSelectList(value);
  List<String> get shareUserSelectList => _shareUserSelectList.value;

  /// AI应用
  set diagnosisModule(List<DiagnosisModuleDTO> v) => _diagnosisModule(v);
  List<DiagnosisModuleDTO> get diagnosisModule => _diagnosisModule.value;

  /// 筛选所在医院列表
  set organizationLocatedList(List<FMutiSelectModel> v) =>
      _organizationLocatedList(v);
  List<FMutiSelectModel> get organizationLocatedList =>
      _organizationLocatedList.value;

  /// 筛选选中所在医院
  set selectedOrganizationLocated(List<String> v) =>
      _selectedOrganizationLocated(v);
  List<String> get selectedOrganizationLocated =>
      _selectedOrganizationLocated.value;

  void refreshDeviceInfo() {
    _deviceInfo.refresh();
  }
}

enum OnlineStatus {
  All,
  Online,
  OffLine,
}
