import 'package:equatable/equatable.dart';

class DeviceInfo extends Equatable {
  final String deviceName;
  final String deviceCode;
  final String location;
  final String status;
  final String voltage;
  final String current;
  final String power;
  final String temperature;
  final List<int> powerData;
  final List<int> tempData;
  final List<String> timeLabels;
  final String deviceTypeIcon;

  const DeviceInfo({
    required this.deviceName,
    required this.deviceCode,
    required this.location,
    required this.status,
    required this.voltage,
    required this.current,
    required this.power,
    required this.temperature,
    required this.powerData,
    required this.tempData,
    required this.timeLabels,
    required this.deviceTypeIcon,
  });

  @override
  List<Object?> get props => [
        deviceName,
        deviceCode,
        location,
        status,
        voltage,
        current,
        power,
        temperature,
        powerData,
        tempData,
        timeLabels,
    deviceTypeIcon,
      ];
}

/// copyWith 中用作 "未传参" 哨兵，区分 "保持原值" 和 "显式设为 null"。
const Object _unset = Object();

class DeviceState extends Equatable {
  final bool isLoading;
  final String? error;
  final DeviceInfo? deviceInfo;
  final bool isPoweringOn;
  final bool isPoweringOff;
  final String? operationMessage;
  final int selectedChartTabIndex;

  const DeviceState({
    this.isLoading = false,
    this.error,
    this.deviceInfo,
    this.isPoweringOn = false,
    this.isPoweringOff = false,
    this.operationMessage,
    this.selectedChartTabIndex = 0,
  });

  DeviceState copyWith({
    bool? isLoading,
    Object? error = _unset,
    Object? deviceInfo = _unset,
    bool? isPoweringOn,
    bool? isPoweringOff,
    Object? operationMessage = _unset,
    int? selectedChartTabIndex,
  }) {
    return DeviceState(
      isLoading: isLoading ?? this.isLoading,
      error: identical(error, _unset) ? this.error : error as String?,
      deviceInfo: identical(deviceInfo, _unset)
          ? this.deviceInfo
          : deviceInfo as DeviceInfo?,
      isPoweringOn: isPoweringOn ?? this.isPoweringOn,
      isPoweringOff: isPoweringOff ?? this.isPoweringOff,
      operationMessage: identical(operationMessage, _unset)
          ? this.operationMessage
          : operationMessage as String?,
      selectedChartTabIndex:
          selectedChartTabIndex ?? this.selectedChartTabIndex,
    );
  }

  @override
  List<Object?> get props => [
        isLoading,
        error,
        deviceInfo,
        isPoweringOn,
        isPoweringOff,
        operationMessage,
        selectedChartTabIndex,
      ];
}