import 'package:equatable/equatable.dart';

class DeviceInfo extends Equatable {
  final String deviceName;
  final String deviceId;
  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;

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

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

/// 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;

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

  DeviceState copyWith({
    bool? isLoading,
    Object? error = _unset,
    Object? deviceInfo = _unset,
    bool? isPoweringOn,
    bool? isPoweringOff,
    Object? operationMessage = _unset,
  }) {
    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?,
    );
  }

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