import 'package:flyinsono/pages/remedical/consultation/widgets/muti_select.dart';
import 'package:get/get.dart';
import 'package:fis_jsonrpc/rpc.dart';

class ConsultationRecordViewState {
  // title
  final _title = "".obs;
  set title(value) => _title.value = value;
  get title => _title.value;
  final Rx<int> _referTab = Rx(0);

  final _selectedTabIndex = RxInt(0);
  final RxList<RemedicalAISelectedInfoDTO> _aiImages =
      RxList<RemedicalAISelectedInfoDTO>();

  final Rx<RemedicalListResult> _remedicalListResult =
      Rx(RemedicalListResult());
  RxList<RemedicalMeasuredInfoDTO> _measureImages =
      RxList<RemedicalMeasuredInfoDTO>();
  final RxList<ReportDTO> _reports = RxList<ReportDTO>();
  final Rx<CarotidScanTypeEnum?> _carotidVAS = Rx(null);

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

  ///报告列表
  List<ReportDTO> get reports => _reports;
  set reports(List<ReportDTO> v) => _reports.value = v;

  ///Tab选中值,云端图像0，测量图像1，报告列表2
  int get selectedTabIndex => _selectedTabIndex.value;
  set selectedTabIndex(int v) => _selectedTabIndex.value = v;

  ///云端图像结果集合（包含所有云端图像）
  RemedicalListResult get remedicalListResult => _remedicalListResult.value;
  set remedicalListResult(RemedicalListResult v) =>
      _remedicalListResult.value = v;

  List<RemedicalInfoDTO> get allCloudImages {
    List<RemedicalInfoDTO> imageInfos = [];
    for (RemedicalItemList info
        in remedicalListResult.remedicalItemList ?? []) {
      ///左颈动脉图像集合
      var carotidLeftImages = info.remedicalList
              ?.where((element) =>
                  element.carotidResult?.carotidScanType ==
                  CarotidScanTypeEnum.CarotidLeft)
              .toList() ??
          [];
      imageInfos.addAll(carotidLeftImages);

      ///右颈动脉图像集合
      var carotidRightImages = info.remedicalList
              ?.where((element) =>
                  element.carotidResult?.carotidScanType ==
                  CarotidScanTypeEnum.CarotidRight)
              .toList() ??
          [];
      imageInfos.addAll(carotidRightImages);

      ///非颈动脉（或未识别左右颈）图像集合
      var notCarotidImages = info.remedicalList
              ?.where(
                (element) => ![
                  CarotidScanTypeEnum.CarotidRight,
                  CarotidScanTypeEnum.CarotidLeft
                ].contains(element.carotidResult?.carotidScanType),
              )
              .toList() ??
          [];
      imageInfos.addAll(notCarotidImages);
    }
    return imageInfos;
  }

  ///测量图像
  List<RemedicalMeasuredInfoDTO> get measureImages => _measureImages;
  set measureImages(List<RemedicalMeasuredInfoDTO> v) =>
      _measureImages.value = v;

  ///AI图像
  List<RemedicalAISelectedInfoDTO> get aiImages => _aiImages;
  set aiImages(List<RemedicalAISelectedInfoDTO> v) => _aiImages.value = v;

  final Rx<List<FMutiSelectModel>> _organizationLocatedList =
      Rx(<FMutiSelectModel>[]);
  final Rx<List<FMutiSelectModel>> _personDeviceList = Rx(<FMutiSelectModel>[]);
  final Rx<List<String>> _selectedOrganizationLocated = Rx(<String>[]);
  final Rx<List<String>> _selectedpersonDevice = Rx(<String>[]);

  ///医院类型
  OrganizationPatientTypeEnum patientType = OrganizationPatientTypeEnum.Person;

  /// 所属医院
  set organizationLocatedList(List<FMutiSelectModel> value) =>
      _organizationLocatedList(value);
  List<FMutiSelectModel> get organizationLocatedList =>
      _organizationLocatedList.value;

  /// 个人设备列表
  set personDeviceList(List<FMutiSelectModel> value) =>
      _personDeviceList(value);
  List<FMutiSelectModel> get personDeviceList => _personDeviceList.value;

  /// 选中的所属医院
  set selectedOrganizationLocated(List<String> value) =>
      _selectedOrganizationLocated(value);
  List<String> get selectedOrganizationLocated =>
      _selectedOrganizationLocated.value;

  /// 选中的个人设备
  set selectedpersonDevice(List<String> value) => _selectedpersonDevice(value);
  List<String> get selectedpersonDevice => _selectedpersonDevice.value;

  /// 转诊申请或者转诊历史
  set referTab(value) => _referTab.value = value;
  get referTab => _referTab.value;
}
