import 'package:equatable/equatable.dart';
import 'package:flutter/widgets.dart';
import 'package:syncrow_web/pages/analytics/models/energy_data_model.dart';

class DeviceEnergyDataModel extends Equatable {
  const DeviceEnergyDataModel({
    required this.energy,
    required this.deviceName,
    required this.deviceId,
    required this.color,
  });

  final List<EnergyDataModel> energy;
  final String deviceName;
  final String deviceId;
  final Color color;

  @override
  List<Object?> get props => [energy, deviceName, deviceId];

  factory DeviceEnergyDataModel.fromJson(Map<String, dynamic> json) {
    final energy = (json['energy'] as List<dynamic>? ?? [])
        .map((e) => EnergyDataModel.fromJson(e))
        .toList();
    return DeviceEnergyDataModel(
      energy: energy,
      deviceName: json['device_name'] as String? ?? '',
      deviceId: json['device_id'] as String? ?? '',
      color: Color(int.parse(json['color'] as String? ?? '0xFF000000')),
    );
  }
}
