2026-04-15 14:43:38 +02:00
|
|
|
import 'package:equatable/equatable.dart';
|
|
|
|
|
|
|
|
|
|
enum EnergyType { luce, gas } // Mappa il tuo public.energy_type
|
|
|
|
|
|
|
|
|
|
class EnergyServiceModel extends Equatable {
|
|
|
|
|
final String? id;
|
|
|
|
|
final DateTime? createdAt;
|
|
|
|
|
final EnergyType type;
|
|
|
|
|
final DateTime expiration;
|
2026-04-15 15:21:19 +02:00
|
|
|
final String providerId;
|
2026-04-15 14:43:38 +02:00
|
|
|
final String? serviceId;
|
|
|
|
|
|
|
|
|
|
const EnergyServiceModel({
|
|
|
|
|
this.id,
|
|
|
|
|
this.createdAt,
|
|
|
|
|
required this.type,
|
|
|
|
|
required this.expiration,
|
2026-04-15 15:21:19 +02:00
|
|
|
required this.providerId,
|
2026-04-15 14:43:38 +02:00
|
|
|
this.serviceId,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
EnergyServiceModel copyWith({
|
|
|
|
|
String? id,
|
|
|
|
|
DateTime? createdAt,
|
|
|
|
|
EnergyType? type,
|
|
|
|
|
DateTime? expiration,
|
2026-04-15 15:21:19 +02:00
|
|
|
String? providerId,
|
2026-04-15 14:43:38 +02:00
|
|
|
String? serviceId,
|
|
|
|
|
}) {
|
|
|
|
|
return EnergyServiceModel(
|
|
|
|
|
id: id ?? this.id,
|
|
|
|
|
createdAt: createdAt ?? this.createdAt,
|
|
|
|
|
type: type ?? this.type,
|
|
|
|
|
expiration: expiration ?? this.expiration,
|
2026-04-15 15:21:19 +02:00
|
|
|
providerId: providerId ?? this.providerId,
|
2026-04-15 14:43:38 +02:00
|
|
|
serviceId: serviceId ?? this.serviceId,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
List<Object?> get props => [
|
|
|
|
|
id,
|
|
|
|
|
createdAt,
|
|
|
|
|
type,
|
|
|
|
|
expiration,
|
2026-04-15 15:21:19 +02:00
|
|
|
providerId,
|
2026-04-15 14:43:38 +02:00
|
|
|
serviceId,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
factory EnergyServiceModel.fromMap(Map<String, dynamic> map) {
|
|
|
|
|
return EnergyServiceModel(
|
|
|
|
|
id: map['id'],
|
|
|
|
|
createdAt: map['created_at'] != null
|
|
|
|
|
? DateTime.parse(map['created_at'])
|
|
|
|
|
: null,
|
|
|
|
|
type: map['type'] == 'gas' ? EnergyType.gas : EnergyType.luce,
|
|
|
|
|
expiration: DateTime.parse(map['expiration']),
|
2026-04-15 15:21:19 +02:00
|
|
|
providerId: map['provider_id'],
|
2026-04-15 14:43:38 +02:00
|
|
|
serviceId: map['service_id'],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> toMap() {
|
|
|
|
|
return {
|
|
|
|
|
if (id != null) 'id': id,
|
|
|
|
|
'type': type.name, // .name trasforma l'enum in 'luce' o 'gas'
|
|
|
|
|
'expiration': expiration.toIso8601String(),
|
2026-04-15 15:21:19 +02:00
|
|
|
'provider_id': providerId,
|
2026-04-15 14:43:38 +02:00
|
|
|
'service_id': serviceId,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|