import 'package:get/get.dart';
import 'package:fis_i18n/i18n.dart';
import '../../common/device_live/device_live_detail/state.dart';

class HardwareDetectionState {
  /// *** 数据层状态 ***
  ///
  /// 数据层状态是指在 [Controller] 中的状态，用于控制数据的获取和存储。

  /// 设备列表
  List<HardwareDevice> deviceList = [];

  /// SP60本地魔盒数据
  DeviceStateModel? _model;
  set model(DeviceStateModel value) => _model = value;
  DeviceStateModel get model => _model!;

  RxBool _isOldVBox = RxBool(true);

  /// *** UI 层状态 ***
  ///
  /// UI 层状态是指在 [View] 中的状态，用于控制页面的显示效果。
  /// UI 层状态通常是通过 [Rx] 类型的变量来实现的。
  /// 摄像头初始化完成
  RxBool _isDisplayCameraWindow = RxBool(false);

  /// 扬声器初始化完成
  RxBool _isDisplaySpeakerWave = RxBool(false);

  /// 麦克风初始化完成
  RxBool _isDisplayMicrophoneWave = RxBool(false);

  /// 摄像头列表
  RxList<HardwareDevice> _cameraList = RxList<HardwareDevice>([]);

  /// 麦克风列表
  RxList<HardwareDevice> _microphoneList = RxList<HardwareDevice>([]);

  /// 扬声器列表
  RxList<HardwareDevice> _speakerList = RxList<HardwareDevice>([]);

  /// 当前选中的摄像头
  Rx<HardwareDevice?> _currentCamera = Rx<HardwareDevice?>(null);

  /// 当前选中的麦克风
  Rx<HardwareDevice?> _currentMicrophone = Rx<HardwareDevice?>(null);

  /// 当前选中的扬声器
  Rx<HardwareDevice?> _currentSpeaker = Rx<HardwareDevice?>(null);

  /// 当前摄像头可用性
  Rx<bool?> _cameraAvailable = Rx(null);

  /// 当前麦克风可用性
  Rx<bool?> _microphoneAvailable = Rx(null);

  /// 当前扬声器可用性
  Rx<bool?> _speakerAvailable = Rx(null);

  /// 是否正在检测摄像头
  RxBool _detectingCamera = RxBool(false);

  /// 是否正在检测麦克风
  RxBool _detectingMicrophone = RxBool(false);

  /// 是否正在检测扬声器
  RxBool _detectingSpeaker = RxBool(false);

  /// 是否正在查找摄像头
  RxBool _searchingCamera = RxBool(true);

  /// 是否正在查找麦克风
  RxBool _searchingMicrophone = RxBool(true);

  /// 是否正在查找扬声器
  RxBool _searchingSpeaker = RxBool(true);

  /// 扬声器音量
  RxDouble _speakerVolume = RxDouble(100);

  RxList<String> _navTitles = RxList<String>([
    i18nBook.setting.start.t,
    i18nBook.setting.cameraDetection.t,
    i18nBook.setting.speakerDetection.t,
    i18nBook.setting.microphoneDetection.t,
    // i18nBook.setting.sonopostDetetion.t,
  ]);

  List<String> get navTitles => _navTitles;

  set navTitles(List<String> val) => _navTitles.value = val;

  /// 魔盒设备唯一码
  RxString _deviceCode = RxString("");

  bool get isOldVBox => _isOldVBox.value;
  set isOldVBox(bool val) => _isOldVBox.value = val;

  set isDisplayMicrophoneWave(bool value) =>
      _isDisplayMicrophoneWave.value = value;
  bool get isDisplayMicrophoneWave => _isDisplayMicrophoneWave.value;

  set isDisplaySpeakerWave(bool value) => _isDisplaySpeakerWave.value = value;
  bool get isDisplaySpeakerWave => _isDisplaySpeakerWave.value;

  set isDisplayCameraWindow(bool value) => _isDisplayCameraWindow.value = value;
  bool get isDisplayCameraWindow => _isDisplayCameraWindow.value;

  set cameraList(List<HardwareDevice> value) => _cameraList.value = value;
  List<HardwareDevice> get cameraList => _cameraList;

  set currentCamera(HardwareDevice? value) => _currentCamera = Rx(value);
  HardwareDevice? get currentCamera => _currentCamera.value;

  set microphoneList(List<HardwareDevice> value) =>
      _microphoneList.value = value;
  List<HardwareDevice> get microphoneList => _microphoneList;

  set currentMicrophone(HardwareDevice? value) =>
      _currentMicrophone = Rx(value);
  HardwareDevice? get currentMicrophone => _currentMicrophone.value;

  set speakerList(List<HardwareDevice> value) => _speakerList.value = value;
  List<HardwareDevice> get speakerList => _speakerList;

  set currentSpeaker(HardwareDevice? value) => _currentSpeaker = Rx(value);
  HardwareDevice? get currentSpeaker => _currentSpeaker.value;

  set cameraAvailable(bool? value) => _cameraAvailable.value = value;
  bool? get cameraAvailable => _cameraAvailable.value;

  set microphoneAvailable(bool? value) => _microphoneAvailable.value = value;
  bool? get microphoneAvailable => _microphoneAvailable.value;

  set speakerAvailable(bool? value) => _speakerAvailable.value = value;
  bool? get speakerAvailable => _speakerAvailable.value;

  set detectingCamera(bool value) => _detectingCamera.value = value;
  bool get detectingCamera => _detectingCamera.value;

  set detectingMicrophone(bool value) => _detectingMicrophone.value = value;
  bool get detectingMicrophone => _detectingMicrophone.value;

  set detectingSpeaker(bool value) => _detectingSpeaker.value = value;
  bool get detectingSpeaker => _detectingSpeaker.value;

  set searchingCamera(bool value) => _searchingCamera.value = value;
  bool get searchingCamera => _searchingCamera.value;

  set searchingMicrophone(bool value) => _searchingMicrophone.value = value;
  bool get searchingMicrophone => _searchingMicrophone.value;

  set searchingSpeaker(bool value) => _searchingSpeaker.value = value;
  bool get searchingSpeaker => _searchingSpeaker.value;

  set speakerVolume(double value) => _speakerVolume.value = value;
  double get speakerVolume => _speakerVolume.value;

  set deviceCode(String value) => _deviceCode.value = value;
  String get deviceCode => _deviceCode.value;
}

class HardwareDevice {
  /// 设备名称
  String name;

  /// 设备id
  String id;

  /// 设备类型
  HardwareDeviceType type;

  HardwareDevice({required this.name, required this.id, required this.type});
}

enum HardwareDeviceType {
  /// 摄像头
  camera,

  /// 扬声器
  speaker,

  /// 麦克风
  microphone,
}
