import 'dart:ui';

import 'package:fis_jsonrpc/rpc.dart';
import 'package:flyinsono/architecture/states/states.dart';
import 'package:flyinsono/architecture/values/features.dart';
export 'package:fis_lib_business_components/index.dart';
import 'package:flyinsono/managers/interfaces/entities/consultation_member.dart';
import 'package:flyinsono/managers/interfaces/entities/live_consultation.dart';
import 'package:get/get.dart';
import 'entitys/play_channel.dart';
import 'state.dart';
import 'package:fis_lib_media_rt/interface/index.dart';

class LiveConsulationState {
  final Rx<LiveConsultation> _liveConsultation = Rx(LiveConsultation());
  final RxMap<String, PlayChannelInfo> _playChannelInfos = RxMap({});
  final Rx<List<ConsultationPageDTO>> _waitInLineForConsulationPatients =
      Rx(<ConsultationPageDTO>[]);
  final Rx<String> _selectedConsultationCode = Rx('');
  final RxBool _isUSDevice = RxBool(true);
  final RxMap<String, ConsultationMember> _statuses = RxMap({});
  final RxInt _seconds = RxInt(0);
  final RxInt _minute = RxInt(0);
  final Rx<ConsultationDetailDTO> _consultationDetailDTO =
      Rx(ConsultationDetailDTO());
  final Rx<List<String>?> _initBoardDatas = Rx(null);
  final Rx<bool> _isVidCapturerRecording = Rx(false);
  final Rx<bool> _isVidFileCapturing = Rx(false);
  final Rx<bool> _isVidFileCapturingByRecording = Rx(false);
  final Rx<DateTime> _vidCapturerStartTime = Rx(DateTime.now());
  final RxInt _captureImageUploadingCount = RxInt(0);
  final RxInt _captureImageUploadOnceSum = RxInt(0);
  final Rx<List<ConsultationFileDTO>> _captureImageList =
      Rx(<ConsultationFileDTO>[]);
  final Rx<bool> _isShowCaptureImageList = Rx(false);

  final Rx<IPlayChannel?> _deviceCameraChannel = Rx(null);
  final Rx<IPlayChannel?> _deviceDesktopChannel = Rx(null);
  final Rx<bool> _isShowDevicePreviewInLeft = Rx(false);
  final Rx<bool> _isShowDeviceCamera = Rx(true);
  final Rx<bool> _isSwitchCameraDevice = Rx(false);
  final Rx<VideoDeviceOutputInfo?> _desktopDeviceInfo = Rx(null);
  final Rx<bool> _isShowVolumeSetting4Mobile = Rx(false);
  final Rx<bool> _isMergedMode = Rx(false);
  final Rx<bool> _isNeedCropDeviceDesktop = Rx(false);
  final Rx<Rect> _mainViewRectInMergedMode = Rx(Rect.zero);

  bool get isUSDevice => _isUSDevice.value;
  set isUSDevice(bool v) => _isUSDevice.value = v;

  ///超声机信息
  VideoDeviceOutputInfo? get desktopDeviceInfo => _desktopDeviceInfo.value;
  set desktopDeviceInfo(VideoDeviceOutputInfo? v) =>
      _desktopDeviceInfo.value = v;
  final Rx<bool> _isFullRecording = Rx(false);
  final Rx<bool> _isFullRecordingPause = Rx(false);
  final RxBool _showRetryButton = RxBool(false);
  final RxBool _isLoading = RxBool(true);
  final RxBool _isMobilePageShowButtons = RxBool(true);

  /// 移动端页面是否显示按钮
  bool get isMobilePageShowButtons => _isMobilePageShowButtons.value;
  set isMobilePageShowButtons(bool v) => _isMobilePageShowButtons.value = v;

  ///超声机加载转圈
  bool get isLoading => _isLoading.value;
  set isLoading(bool v) => _isLoading.value = v;

  ///超声机重试
  bool get showRetryButton => _showRetryButton.value;
  set showRetryButton(bool v) => _showRetryButton.value = v;

  ///超声机桌面频道
  IPlayChannel? get deviceDesktopChannel => _deviceDesktopChannel.value;
  set deviceDesktopChannel(IPlayChannel? v) => _deviceDesktopChannel.value = v;

  ///是否在主区域显示扫查手法（是否切换超声画面和扫查手法）
  bool get isSwitchCameraDevice => _isSwitchCameraDevice.value;
  set isSwitchCameraDevice(bool v) => _isSwitchCameraDevice.value = v;

  ///是否显示扫查手法（最小化则不显示）
  bool get isShowDeviceCamera => _isShowDeviceCamera.value;
  set isShowDeviceCamera(bool v) => _isShowDeviceCamera.value = v;

  ///扫查手法位置在左侧还是右侧
  bool get isShowDevicePreviewInLeft => _isShowDevicePreviewInLeft.value;
  set isShowDevicePreviewInLeft(bool v) => _isShowDevicePreviewInLeft.value = v;

  ///超声机摄像头频道
  IPlayChannel? get deviceCameraChannel => _deviceCameraChannel.value;
  set deviceCameraChannel(IPlayChannel? v) => _deviceCameraChannel.value = v;

  ///播放频道Map,key:userId
  Map<String, PlayChannelInfo> get playChannels => _playChannelInfos;
  set playChannels(Map<String, PlayChannelInfo> v) =>
      _playChannelInfos.value = v;
  final Rx<PaintType> _paintType = Rx(PaintType.curvedLine);

  ///成员在房间中的状态 key: memberId
  Map<String, ConsultationMember> get memberStatus => _statuses;
  set memberStatus(Map<String, ConsultationMember> v) => _statuses.value = v;

  ///当前病人的会诊Code
  String get selectedConsultationCode => _selectedConsultationCode.value;
  set selectedConsultationCode(String value) =>
      _selectedConsultationCode.value = value;

  ///待会诊的病人列表
  List<ConsultationPageDTO> get waitInLineForConsulationPatients =>
      _waitInLineForConsulationPatients.value;
  set waitInLineForConsulationPatients(List<ConsultationPageDTO> v) =>
      _waitInLineForConsulationPatients.value = v;

  ///会诊记录详情
  ConsultationDetailDTO get consultationDetail => _consultationDetailDTO.value;
  set consultationDetail(ConsultationDetailDTO c) =>
      _consultationDetailDTO.value = c;

  bool get isEmergency => consultationDetail.isEmergency;

  /// 会诊详情
  LiveConsultation get liveConsultation => _liveConsultation.value;
  set liveConsultation(LiveConsultation val) => _liveConsultation.value = val;

  /// 会诊详情
  PaintType get paintType => _paintType.value;
  set paintType(PaintType val) => _paintType.value = val;

  ///时间 秒数
  int get seconds => _seconds.value;
  set seconds(int v) => _seconds.value = v;

  ///时间 分钟
  int get minute => _minute.value;
  set minute(int v) => _minute.value = v;

  /// 初始化白板数据
  List<String>? get initBoardDatas => _initBoardDatas.value;
  set initBoardDatas(List<String>? v) => _initBoardDatas.value = v;

  /// vid 录制器状态
  bool get isVidCapturerRecording => _isVidCapturerRecording.value;
  set isVidCapturerRecording(bool v) => _isVidCapturerRecording.value = v;

  /// vid 开始录制时间
  DateTime get vidCapturerStartTime => _vidCapturerStartTime.value;
  set vidCapturerStartTime(DateTime v) => _vidCapturerStartTime.value = v;

  /// vid 录制中等待状态
  bool get isVidFileCapturing => _isVidFileCapturing.value;
  set isVidFileCapturing(bool v) => _isVidFileCapturing.value = v;

  /// vid 录制中等待状态 [由录制引发的加载]
  bool get isVidFileCapturingByRecording =>
      _isVidFileCapturingByRecording.value;
  set isVidFileCapturingByRecording(bool v) =>
      _isVidFileCapturingByRecording.value = v;

  /// 是否为合图模式
  bool get isMergedMode => _isMergedMode.value;
  set isMergedMode(bool v) => _isMergedMode.value = v;

  /// 是否需要裁切超声机画面
  bool get isNeedCropDeviceDesktop => _isNeedCropDeviceDesktop.value;
  set isNeedCropDeviceDesktop(bool v) => _isNeedCropDeviceDesktop.value = v;

  /// 超声机主画面在总画面的总占比
  Rect get mainViewRectInMergedMode => _mainViewRectInMergedMode.value;
  set mainViewRectInMergedMode(Rect v) => _mainViewRectInMergedMode.value = v;

  ///是否展示截图列表
  bool get isShowCaptureImageList => _isShowCaptureImageList.value;
  set isShowCaptureImageList(bool v) => _isShowCaptureImageList.value = v;

  ///  上传队列中的截图数量
  int get captureImageUploadingCount => _captureImageUploadingCount.value;
  set captureImageUploadingCount(int v) =>
      _captureImageUploadingCount.value = v;

  /// 每轮次上传的截图总数量
  int get captureImageUploadOnceSum => _captureImageUploadOnceSum.value;
  set captureImageUploadOnceSum(int v) => _captureImageUploadOnceSum.value = v;

  /// 是否正在全程录制
  bool get isFullRecording => _isFullRecording.value;
  set isFullRecording(bool v) => _isFullRecording.value = v;

  /// 是否暂停录制
  bool get isFullRecordingPause => _isFullRecordingPause.value;
  set isFullRecordingPause(bool v) => _isFullRecordingPause.value = v;

  /// 是否显示手机端音量设置
  bool get isShowVolumeSetting4Mobile => _isShowVolumeSetting4Mobile.value;
  set isShowVolumeSetting4Mobile(bool v) =>
      _isShowVolumeSetting4Mobile.value = v;

  /// 截图、录制的图片列表
  List<ConsultationFileDTO> get captureImageList => _captureImageList.value;
  set captureImageList(List<ConsultationFileDTO> v) =>
      _captureImageList.value = v;

  bool get canRemoteParameter =>
      Store.user.hasFeature(FeatureKeys.RemoteParameter) &&
      consultationDetail.expertUserCode == Store.user.code;
}

///待会诊病人信息
class PatientInfo {
  String name;

  String id;

  PatientInfo(this.name, this.id);
}
