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

class PatientDetailState {
  final Rx<PatientDTO> _dto = Rx<PatientDTO>(
    PatientDTO(
      patientName: "",
      patientGender: GenderEnum.Unknown,
      phone: "",
      birthday: DateTime(1900, 1, 1),
      patientAddress: "",
      crowdLabels: null,
      contractedDoctorName: '',
    ),
  );

  /// 病人编号
  String code = "";

  /// 姓名
  String get name => _dto.value.patientName!;

  /// 年龄
  String get age => DataTimeUtils.calculateAge(_dto.value.birthday!);

  /// 手机号
  String get phone => _dto.value.phone!;

  /// 地址
  String get address => _dto.value.patientAddress!;

  /// 头像URL
  String? get avatarUrl => null; //TODO:

  /// 性别
  GenderEnum get gender => _dto.value.patientGender;

  /// 性别描述
  String get genderDesc => RpcEnumLabels.gender[gender]!;

  /// 人群分类名称集合
  List<String>? get labelNames => _dto.value.labelNames;

  List<String>? get crowdLabels => _dto.value.crowdLabels;

  /// 签约医生
  String get contractedDoctorName => _dto.value.contractedDoctorName!;

  String get cardNo => _dto.value.cardNo ?? "";

  /// 签约状态
  ContractStateEnum get contractState => _dto.value.contractState;

  void updateDto(PatientDTO dto) {
    _dto.value = dto;
  }

  void updateCrowd(List<String> crowdCodes, List<String> crowdNames) {
    final newDto = PatientDTO.fromJson(_dto.value.toJson());
    newDto.crowdLabels = crowdCodes;
    newDto.labelNames = crowdNames;
    _dto.value = newDto;
  }
}
