import 'dart:collection';

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 ServicePackageContractState {
  /// 病人编号
  String patientCode = "";

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

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

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

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

  /// 性别
  String get genderDesc => RpcEnumLabels.gender[_dto.value.patientGender]!;

  /// 人群分类编号集合
  List<String>? get crowdLabelCodes => _dto.value.crowdLabels;
  // final RxList<dynamic> _servicePackageItems = RxList.empty();
  final RxList<ServicePackDTO> _servicePackageItems = RxList();

  final RxList<ServiceItemDTO> _serviceItems = RxList();

  final RxList<ServicePackDTO> _selectedServicePackage =
      RxList<ServicePackDTO>();
  final RxString _selectedServicePackageName = RxString('');
  final RxString _selectedServicePackageCode = RxString('');
  final Rx<PatientDTO> _dto = Rx<PatientDTO>(
    PatientDTO(
      patientName: "",
      patientGender: GenderEnum.Unknown,
      phone: "",
      birthday: DateTime(1900, 1, 1),
      patientAddress: "",
      crowdLabels: null,
    ),
  );

  final Rx<DateTime> _serviceStartDate = Rx(DateTime.now());

  final RxBool _isExpendPatient = RxBool(false);

  /// 服务包集合
  List<ServicePackDTO> get servicePackageItems =>
      UnmodifiableListView(_servicePackageItems.toList());
  set servicePackageItems(List<ServicePackDTO> val) =>
      _servicePackageItems.value = val;

  /// 服务包集合
  List<ServiceItemDTO> get serviceItems =>
      UnmodifiableListView(_serviceItems.toList());
  set serviceItems(List<ServiceItemDTO> val) => _serviceItems.value = val;

  /// 选择的服务包集合
  List<ServicePackDTO> get selectedServicePackage =>
      _selectedServicePackage.toList();
  set selectedServicePackage(List<ServicePackDTO> val) =>
      _selectedServicePackage.value = val;

  /// 服务包名
  String get selectedServicePackageName => _selectedServicePackageName.value;
  set selectedServicePackageName(String val) =>
      _selectedServicePackageName.value = val;

  /// 服务包code
  String get selectedServicePackageCode => _selectedServicePackageCode.value;
  set selectedServicePackageCode(String val) =>
      _selectedServicePackageCode.value = val;

  /// 是否展开
  bool get isExpendPatient => _isExpendPatient.value;
  set isExpendPatient(bool val) => _isExpendPatient.value = val;

  /// 服务开始时间
  DateTime get serviceStartDate => _serviceStartDate.value;
  set serviceStartDate(DateTime val) => _serviceStartDate.value = val;

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