import 'dart:collection';

import 'package:fis_jsonrpc/rpc.dart';
import 'package:flutter/widgets.dart';
import 'package:flyinsono/managers/interfaces/entities/device_entities.dart';
import 'package:get/get.dart';
import 'package:flyinsono/architecture/define.dart';

import '../device_live_list/state.dart';

/// 超声直播面板状态
class DeviceLiveDetailState extends DeviceLiveListBaseState {
  final _deviceList = FRxList<DeviceStateModel>([]);

  /// 设备列表
  UnmodifiableListView<DeviceStateModel> get deviceList =>
      UnmodifiableListView(_deviceList);
  @protected
  set deviceList(List<DeviceStateModel> val) => _deviceList.value = val;

  /// 补充设备列表
  void appendDeviceList(List<DeviceExtendInfoDTO> dtoList) {
    final models = dtoList.map((e) => DeviceStateModel(e));
    _deviceList.addAll(models);
  }

  /// 更新设备列表
  void updateDeviceList(List<DeviceExtendInfoDTO> dtoList) {
    final models = dtoList.map((e) => DeviceStateModel(e));
    _deviceList.value = models.toList();
  }
}

class DeviceStateModel {
  DeviceStateModel(this.dto, {this.liveInfo});

  final _isChecked = RxBool(false);

  /// 数据实例
  DeviceExtendInfoDTO dto;

  /// 直播信息
  DeviceLiveDisplayInfoModel? liveInfo;

  /// 是否被选中
  bool get isChecked => _isChecked.value;
  set isChecked(bool val) => _isChecked.updateValue(val);
}
