import 'package:fis_jsonrpc/rpc.dart';
import 'package:flyinsono/managers/interfaces/entities/reportEditSource.dart';
import 'package:get/get.dart';
import 'package:fis_ui/index.dart';
import 'entitys/report_tag_key.dart';

class ReportEditState {
  final Rx<ReportTemplateDTO> _selectedTemplate = Rx(ReportTemplateDTO());
  final RxMap<ReportTagKey, List<String>> _allReportTags =
      RxMap<ReportTagKey, List<String>>();
  final RxList<String> _selectedTags = RxList<String>();
  final RxList<String> _selectClassifications = RxList<String>();
  final RxMap<ReportTagKey, String> _selectedLabes =
      RxMap<ReportTagKey, String>();
  final RxMap<String, ThesaurusAllDTO> _entrys =
      RxMap(<String, ThesaurusAllDTO>{});
  final RxList<FSelectOptionModel<String?>> _templates =
      RxList(<FSelectOptionModel<String?>>[]);

  final Rx<int> _selectImageIndex = Rx(0);
  final Rx<List<VocabularyEntryModel>> _vocabularyEntryList =
      Rx(<VocabularyEntryModel>[]);
  final Rx<String> _selectedTag = Rx('');
  final Rx<String> _selectedClassification = Rx('');
  final RxList<ThesaurusDTO> _entryInfos = RxList(<ThesaurusDTO>[]);

  ///病人信息，（用于初始化报告中一些字段）
  final Rx<String> _patientName = Rx('');
  final Rx<String> _patientId = Rx('');
  final RxString _selectedEntryCode = RxString('');
  final Rx<String> _patientSex = Rx('');
  final Rx<String> _patientAge = Rx('');
  final Rx<String> _orgName = Rx('');
  final Rx<String> _referralRecordCode = Rx('');
  final Rx<String> _reportCode = Rx('');
  final Rx<String> _recordCode = Rx('');
  final Rx<String> _consultationCode = Rx('');
  final Rx<bool> _isRemeber = Rx(false);
  final Rx<bool> _isEntryDisplayed = Rx(false);
  final RxList<ConsultationFileDTO> _consultationImages =
      RxList(<ConsultationFileDTO>[]);
  final RxList<RemedicalInfoDTO> _remedicalItemList =
      RxList<RemedicalInfoDTO>();
  final RxList<String> _selectedImages = RxList(<String>[]);
  final Rx<List<RemedicalMeasuredInfoDTO>> _remedicalMeasured =
      Rx(<RemedicalMeasuredInfoDTO>[]);
  final Rx<List<RemedicalAISelectedInfoDTO>> _remedicalAISelectedInfos =
      Rx(<RemedicalAISelectedInfoDTO>[]);
  final RxList<RemedicalInfoDTO> _cloudCarotidLeftImages =
      RxList<RemedicalInfoDTO>();
  final RxList<RemedicalInfoDTO> _cloudCarotidRightImages =
      RxList<RemedicalInfoDTO>();
  final Rx<CarotidScanTypeEnum?> _carotidVAS = Rx(null);
  final RxList<ThesaurusItemDTO> _allThesaurusList =
      RxList(<ThesaurusItemDTO>[]);

  ///所有词条信息
  List<ThesaurusDTO> get entryInfos => _entryInfos;
  set entryInfos(List<ThesaurusDTO> v) => _entryInfos.value = v;

  ///所有词条项（树形结构中的所有节点）
  List<ThesaurusItemDTO> get allThesaurusList => _allThesaurusList;
  set allThesaurusList(List<ThesaurusItemDTO> v) => _allThesaurusList.value = v;

  ///选中的词条
  String get selectedEntryCode => _selectedEntryCode.value;
  set selectedEntryCode(String v) => _selectedEntryCode.value = v;

  ///是否显示词条
  bool get isEntryDisplayed => _isEntryDisplayed.value;
  set isEntryDisplayed(bool v) => _isEntryDisplayed.value = v;

  ///模板列表
  List<FSelectOptionModel<String?>> get templates => _templates;
  set templates(List<FSelectOptionModel<String?>> v) => _templates.value = v;

  CarotidScanTypeEnum? get carotidVAS => _carotidVAS.value;
  set carotidVAS(CarotidScanTypeEnum? v) => _carotidVAS.value = v;

  ///已选中的图像
  List<String> get selectedImages => _selectedImages;
  set selectedImages(List<String> v) => _selectedImages.value = v;

  ///会诊图片
  List<ConsultationFileDTO> get consultationImages => _consultationImages;
  set consultationImages(List<ConsultationFileDTO> consultationImages) {
    _consultationImages.value = consultationImages;
  }

  /// 测量图像
  set remedicalMeasured(List<RemedicalMeasuredInfoDTO> value) =>
      _remedicalMeasured(value);
  List<RemedicalMeasuredInfoDTO> get remedicalMeasured =>
      _remedicalMeasured.value;

  /// AI图像
  set remedicalAISelectedInfos(List<RemedicalAISelectedInfoDTO> value) =>
      _remedicalAISelectedInfos(value);
  List<RemedicalAISelectedInfoDTO> get remedicalAISelectedInfos =>
      _remedicalAISelectedInfos.value;

  ///是否记住不再提醒
  bool get isRemeber => _isRemeber.value;
  set isRemeber(bool v) => _isRemeber.value = v;

  ///组织名称
  String get orgName => _orgName.value;
  set orgName(String name) => _orgName.value = name;

  ///转诊Code
  String get referralRecordCode => _referralRecordCode.value;
  set referralRecordCode(String name) => _referralRecordCode.value = name;

  ///当前标签
  String get selectedTag => _selectedTag.value;
  set selectedTag(String name) => _selectedTag.value = name;

  ///当前分类
  String get selectedClassification => _selectedClassification.value;
  set selectedClassification(String name) =>
      _selectedClassification.value = name;

  ///分类列表
  List<String> get selectClassifications => _selectClassifications;
  set selectClassifications(List<String> value) =>
      _selectClassifications.value = value;

  ///选中分类
  Map<ReportTagKey, String> get selectedLabes => _selectedLabes;
  set selectedLabes(Map<ReportTagKey, String> value) =>
      _selectedLabes.value = value;

  ///标签列表
  Map<ReportTagKey, List<String>> get allReportTags => _allReportTags;
  set allReportTags(Map<ReportTagKey, List<String>> value) =>
      _allReportTags.value = value;

  ///选中标签列表
  List<String> get selectedTags => _selectedTags;
  set seletedTags(List<String> value) => _selectedTags.value = value;

  ///所有图像信息（不含左颈右颈）
  List<RemedicalInfoDTO> get remedicalItemList => _remedicalItemList;
  set remedicalItemList(List<RemedicalInfoDTO> values) =>
      _remedicalItemList.value = values;

  ///左颈动脉图像
  List<RemedicalInfoDTO> get cloudCarotidLeftImages => _cloudCarotidLeftImages;
  set cloudCarotidLeftImages(List<RemedicalInfoDTO> v) =>
      _cloudCarotidLeftImages.value = v;

  ///右颈动脉图像
  List<RemedicalInfoDTO> get cloudCarotidRightImages =>
      _cloudCarotidRightImages;
  set cloudCarotidRightImages(List<RemedicalInfoDTO> v) =>
      _cloudCarotidRightImages.value = v;

  /// 报告Id
  set reportCode(String value) => _reportCode.value = value;
  String get reportCode => _reportCode.value;

  /// 病例Code
  set recordCode(String value) => _recordCode.value = value;
  String get recordCode => _recordCode.value;

  /// 会诊Code
  set consultationCode(String value) => _consultationCode.value = value;
  String get consultationCode => _consultationCode.value;

  /// 病人Id
  set patientId(String value) => _patientId.value = value;
  String get patientId => _patientId.value;

  /// 病人年龄
  set patientAge(String value) => _patientAge.value = value;
  String get patientAge => _patientAge.value;

  /// 病人性别
  set patientSex(String value) => _patientSex.value = value;
  String get patientSex => _patientSex.value;

  /// 病人名
  set patientName(String value) => _patientName.value = value;
  String get patientName => _patientName.value;

  ///病人ID
  String devicePatientId = '';

  ///当前选中的模板
  ReportTemplateDTO get selectedTemplate => _selectedTemplate.value;
  set selectedTemplate(ReportTemplateDTO value) =>
      _selectedTemplate.value = value;

  /// 选中图片位置
  set selectImageTabIndex(int value) => _selectImageIndex.value = value;
  int get selectImageTabIndex => _selectImageIndex.value;

  ///报告词条
  List<VocabularyEntryModel> get vocabularyEntryList =>
      _vocabularyEntryList.value;
  set vocabularyEntryList(List<VocabularyEntryModel> value) =>
      _vocabularyEntryList.value = value;

  ///报告编辑的来源
  ReportEditSource? reportEditSource;
}

class VocabularyEntryModel {
  VocabularyEntryModel({
    required this.title,
    required this.code,
  });
  final String title;
  final String code;
}
