import 'package:equatable/equatable.dart';

class ZoneData extends Equatable {
  final String name;
  final double percentage;
  final double energy;

  const ZoneData({
    required this.name,
    required this.percentage,
    required this.energy,
  });

  @override
  List<Object?> get props => [name, percentage, energy];
}

class EnergyState extends Equatable {
  final bool isLoading;
  final String? error;
  final double todayEnergy;
  final double todayEnergyChange;
  final double monthEnergy;
  final double monthEnergyChange;
  final double monthBill;
  final double hourlyMaxValue;
  final List<double> hourlyData;
  final List<ZoneData> zoneData;

  const EnergyState({
    this.isLoading = false,
    this.error,
    this.todayEnergy = 1284,
    this.todayEnergyChange = -8,
    this.monthEnergy = 38420,
    this.monthEnergyChange = -5,
    this.monthBill = 6982,
    this.hourlyMaxValue = 0,
    this.hourlyData = const [],
    this.zoneData = const [
      ZoneData(name: '客房区域', percentage: 68, energy: 873),
      ZoneData(name: '公共区域', percentage: 18, energy: 231),
      ZoneData(name: '餐饮区域', percentage: 10, energy: 128),
      ZoneData(name: '其他', percentage: 4, energy: 52),
    ],
  });

  EnergyState copyWith({
    bool? isLoading,
    String? error,
    double? todayEnergy,
    double? todayEnergyChange,
    double? monthEnergy,
    double? monthEnergyChange,
    double? monthBill,
    double? hourlyMaxValue,
    List<double>? hourlyData,
    List<ZoneData>? zoneData,
    bool clearError = false,
  }) {
    return EnergyState(
      isLoading: isLoading ?? this.isLoading,
      error: clearError ? null : (error ?? this.error),
      todayEnergy: todayEnergy ?? this.todayEnergy,
      todayEnergyChange: todayEnergyChange ?? this.todayEnergyChange,
      monthEnergy: monthEnergy ?? this.monthEnergy,
      monthEnergyChange: monthEnergyChange ?? this.monthEnergyChange,
      monthBill: monthBill ?? this.monthBill,
      hourlyMaxValue: hourlyMaxValue ?? this.hourlyMaxValue,
      hourlyData: hourlyData ?? this.hourlyData,
      zoneData: zoneData ?? this.zoneData,
    );
  }

  @override
  List<Object?> get props => [
        isLoading,
        error,
        todayEnergy,
        todayEnergyChange,
        monthEnergy,
        monthEnergyChange,
        monthBill,
        hourlyMaxValue,
        hourlyData,
        zoneData,
      ];
}
