import 'package:equatable/equatable.dart';

class ServiceDeviceState extends Equatable {
  final bool isLoading;
  final String? error;
  final bool isOperating; // 操作进行中（防重复提交）
  final int deviceId;
  final bool isOn;
  final int targetTemperature;
  final int currentTemperature;
  final int minTemperature;
  final int maxTemperature;
  final List<Map<String, dynamic>> modeData;
  final String currentSpeed;
  final List<String> speedOptions;

  const ServiceDeviceState({
    this.isLoading = false,
    this.error,
    this.isOperating = false,
    this.deviceId = 0,
    this.isOn = true,
    this.targetTemperature = 24,
    this.currentTemperature = 26,
    this.minTemperature = 16,
    this.maxTemperature = 30,
    this.modeData = const [],
    this.currentSpeed = '自动',
    this.speedOptions = const ['自动', '低', '中', '高'],
  });

  ServiceDeviceState copyWith({
    bool? isLoading,
    String? error,
    bool? isOperating,
    int? deviceId,
    bool? isOn,
    int? targetTemperature,
    int? currentTemperature,
    int? minTemperature,
    int? maxTemperature,
    List<Map<String, dynamic>>? modeData,
    String? currentSpeed,
    List<String>? speedOptions,
    bool clearError = false,
  }) {
    return ServiceDeviceState(
      isLoading: isLoading ?? this.isLoading,
      error: clearError ? null : (error ?? this.error),
      isOperating: isOperating ?? this.isOperating,
      deviceId: deviceId ?? this.deviceId,
      isOn: isOn ?? this.isOn,
      targetTemperature: targetTemperature ?? this.targetTemperature,
      currentTemperature: currentTemperature ?? this.currentTemperature,
      minTemperature: minTemperature ?? this.minTemperature,
      maxTemperature: maxTemperature ?? this.maxTemperature,
      modeData: modeData ?? this.modeData,
      currentSpeed: currentSpeed ?? this.currentSpeed,
      speedOptions: speedOptions ?? this.speedOptions,
    );
  }

  @override
  List<Object?> get props => [
        isLoading,
        error,
        isOperating,
        deviceId,
        isOn,
        targetTemperature,
        currentTemperature,
        minTemperature,
        maxTemperature,
        modeData,
        currentSpeed,
        speedOptions,
      ];
}
