import 'dart:collection';

import 'package:fis_jsonrpc/rpc.dart';
import 'package:get/get.dart';
import 'package:vnoteapp/architecture/defines.dart';
import 'package:vnoteapp/architecture/utils/datetime.dart';

class CreatePatientState {
  final RxBool _isCreateOnly = RxBool(false);

  final RxString _name = RxString("");
  final RxString _personalNo = RxString("");
  final RxString _phoneNo = RxString("");
  final Rx<CardTypeEnum> _cardType = Rx<CardTypeEnum>(CardTypeEnum.Identity);
  final RxString _cardNo = RxString("");
  final RxString _nation = RxString("");
  final Rx<GenderEnum> _gender = Rx<GenderEnum>(GenderEnum.Male);
  final Rx<DateTime> _birthday = Rx<DateTime>(DateTime(1970, 1, 1));
  final RxInt _age = RxInt(DataTimeUtils.calculateAge(DateTime(1970, 1, 1)));
  final RxString _censusRegister = RxString("");
  final RxString _address = RxString("");
  final RxString _villageCode = RxString("");
  final RxList<String> _crowdLabelCodes = RxList();
  final RxBool _isSyncAddresses = RxBool(false);

  /// 是否只创建档案
  bool get isCreateOnly => _isCreateOnly.value;
  set isCreateOnly(bool val) => _isCreateOnly.updateValue(val);

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

  /// 个人编号
  String get personalNo => _personalNo.value;
  set personalNo(String val) => _personalNo.updateValue(val);

  /// 手机号
  String get phoneNo => _phoneNo.value;
  set phoneNo(String val) => _phoneNo.updateValue(val);

  /// 证件类型
  CardTypeEnum get cardType => _cardType.value;
  set cardType(CardTypeEnum val) => _cardType.updateValue(val);

  /// 证件号
  String get cardNo => _cardNo.value;
  set cardNo(String val) => _cardNo.updateValue(val);

  /// 民族
  String get nation => _nation.value;
  set nation(String val) => _nation.updateValue(val);

  /// 性别
  GenderEnum get gender => _gender.value;
  set gender(GenderEnum val) => _gender.updateValue(val);

  /// 户籍地址
  String get censusRegister => _censusRegister.value;
  set censusRegister(String val) => _censusRegister.updateValue(val);

  /// 现住址
  String get address => _address.value;
  set address(String val) => _address.updateValue(val);

  /// 村/居委会 编号
  String get villageCode => _villageCode.value;
  set villageCode(String val) => _villageCode.updateValue(val);

  /// 人群分类集合
  List<String> get crowdLabelCodes =>
      UnmodifiableListView(_crowdLabelCodes.toList());
  set crowdLabelCodes(List<String> val) => _crowdLabelCodes.value = val;

  /// 生日
  DateTime get birthday => _birthday.value;
  set birthday(DateTime val) {
    if (val != _birthday.value) {
      _birthday.value = val;
      _age.value = DataTimeUtils.calculateAge(val);
    }
  }

  /// 年龄
  int get age => _age.value;

  /// 是否开启地址同步
  bool get isSyncAddresses => _isSyncAddresses.value;
  set isSyncAddresses(bool val) => _isSyncAddresses.updateValue(val);
}
