import 'package:equatable/equatable.dart';

class PhasesEnergyConsumption extends Equatable {
  final String uuid;
  final DateTime createdAt;
  final DateTime updatedAt;
  final String deviceUuid;
  final DateTime date;
  final double energyConsumedKw;
  final double energyConsumedA;
  final double energyConsumedB;
  final double energyConsumedC;

  const PhasesEnergyConsumption({
    required this.uuid,
    required this.createdAt,
    required this.updatedAt,
    required this.deviceUuid,
    required this.date,
    required this.energyConsumedKw,
    required this.energyConsumedA,
    required this.energyConsumedB,
    required this.energyConsumedC,
  });

  @override
  List<Object?> get props => [
        uuid,
        createdAt,
        updatedAt,
        deviceUuid,
        date,
        energyConsumedKw,
        energyConsumedA,
        energyConsumedB,
        energyConsumedC,
      ];

  factory PhasesEnergyConsumption.fromJson(Map<String, dynamic> json) {
    return PhasesEnergyConsumption(
      uuid: json['uuid'] as String,
      createdAt: DateTime.parse(json['createdAt'] as String),
      updatedAt: DateTime.parse(json['updatedAt'] as String),
      deviceUuid: json['deviceUuid'] as String,
      date: DateTime.parse(json['date'] as String),
      energyConsumedKw: double.parse(json['energyConsumedKw']),
      energyConsumedA: double.parse(json['energyConsumedA']),
      energyConsumedB: double.parse(json['energyConsumedB']),
      energyConsumedC: double.parse(json['energyConsumedC']),
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'uuid': uuid,
      'createdAt': createdAt.toIso8601String(),
      'updatedAt': updatedAt.toIso8601String(),
      'deviceUuid': deviceUuid,
      'date': date.toIso8601String().split('T')[0],
      'energyConsumedKw': energyConsumedKw.toString(),
      'energyConsumedA': energyConsumedA.toString(),
      'energyConsumedB': energyConsumedB.toString(),
      'energyConsumedC': energyConsumedC.toString(),
    };
  }
}
