import 'package:fis_common/extensions/string.dart';
import 'package:fis_common/helpers/string_util.dart';
import 'package:fis_jsonrpc/services/organization.m.dart';
import 'package:get/get.dart';

///个人信息完善页面状态
class ProfileCompleteState {
  final Rx<bool> _isChinaArea = Rx(false);
  final Rx<String> _areaDisplayName = Rx('');
  final Rx<String> _countryCode = Rx('');
  final Rx<String> _provinceCode = Rx('');
  final Rx<String> _cityCode = Rx('');
  final Rx<String> _name = Rx('');
  final Rx<String> _mobile = Rx('');
  final Rx<String> _email = Rx('');
  final Rx<String> _hospitalName = Rx('');
  final Rx<String> _roleCode = Rx('');
  final Rx<String> _jobTitleCode = Rx('');
  final Rx<DateTime> _createTime = Rx(DateTime.now());
  final _departmentOptions = Rx<List<DepartmentModel>>([]);
  final _departmentSelection = Rxn<String>();

  List<OrganizationDTO> hospitalDtoList = [];

  int pageIndex = 1;

  /// 姓名
  set name(String value) => _name(value);
  String get name => _name.value;

  /// 手机号
  set mobile(String value) => _mobile(value);
  String get mobile => _mobile.value;

  /// 邮箱
  set email(String value) => _email(value);
  String get email => _email.value;

  /// 医院名称
  set hospitalName(String value) => _hospitalName(value);
  String get hospitalName => _hospitalName.value;

  /// 地区外显名称
  set areaDisplayName(String value) => _areaDisplayName(value);
  String get areaDisplayName => _areaDisplayName.value;

  /// 国家Code
  set countryCode(String? value) => _countryCode(value);
  String? get countryCode => _countryCode.value;

  /// 省份Code
  set provinceCode(String value) => _provinceCode(value);
  String get provinceCode => _provinceCode.value;

  /// 城市Code
  set cityCode(String? value) => _cityCode(value);
  String? get cityCode => _cityCode.value;

  /// 是否中国地区
  bool get isChinaArea => _isChinaArea.value;
  set isChinaArea(bool value) => _isChinaArea(value);

  /// 角色Code
  set roleCode(String value) => _roleCode(value);
  String get roleCode => _roleCode.value;

  /// 职称Code
  set jobTitleCode(String value) => _jobTitleCode(value);
  String get jobTitleCode => _jobTitleCode.value;

  set createTime(DateTime value) => _createTime(value);
  DateTime get createTime => _createTime.value;

  /// 部门选项列表
  List<DepartmentModel> get departmentOptions => _departmentOptions.value;
  set departmentOptions(List<DepartmentModel> value) {
    _departmentOptions.value = value;
    departmentSelection = null;
  }

  /// 当前选中部门选项
  String? get departmentSelection => _departmentSelection.value;
  set departmentSelection(String? value) => _departmentSelection.value = value;
}

///个人信息完善表单验证状态
class ProfileCompleteFormValidateState {
  ProfileCompleteFormValidateState(this.data);

  final ProfileCompleteState data;

  bool get realNameValid => data.name.isNotNullOrWhiteSpace;
  bool get mobileValid =>
      data.mobile.isEmpty || data.mobile.isChineseMobileNumber;
  bool get emailValid => data.email.isEmpty || StringUtil.isEmail(data.email);
  bool get hospitalValid => data.hospitalName.isNotNullOrWhiteSpace;
}

///个人信息完善编辑状态
class ProfileCompleteFormEditState {
  final _nameEdited = false.obs;

  bool get nameEdited => _nameEdited.value;
  set nameEdited(bool val) => _nameEdited.value = val;
}

///部门数据结构模型
class DepartmentModel {
  DepartmentModel({
    required this.title,
    required this.code,
  });
  final String title;
  final String code;
}

///医院数据结构模型
class HospitalModel {
  HospitalModel({
    required this.title,
  });
  final String title;
}

///角色数据结构模型
class RoleModel {
  RoleModel({required this.name, required this.code});
  final String name;
  final String code;
}
