73 lines
1.8 KiB
Dart
73 lines
1.8 KiB
Dart
import 'package:equatable/equatable.dart';
|
|
|
|
enum EnergyType { luce, gas } // Mappa il tuo public.energy_type
|
|
|
|
class EnergyOperationModel extends Equatable {
|
|
final String? id;
|
|
final DateTime? createdAt;
|
|
final EnergyType type;
|
|
final DateTime expiration;
|
|
final String providerId;
|
|
final String? operationId;
|
|
|
|
const EnergyOperationModel({
|
|
this.id,
|
|
this.createdAt,
|
|
required this.type,
|
|
required this.expiration,
|
|
required this.providerId,
|
|
this.operationId,
|
|
});
|
|
|
|
EnergyOperationModel copyWith({
|
|
String? id,
|
|
DateTime? createdAt,
|
|
EnergyType? type,
|
|
DateTime? expiration,
|
|
String? providerId,
|
|
String? operationId,
|
|
}) {
|
|
return EnergyOperationModel(
|
|
id: id ?? this.id,
|
|
createdAt: createdAt ?? this.createdAt,
|
|
type: type ?? this.type,
|
|
expiration: expiration ?? this.expiration,
|
|
providerId: providerId ?? this.providerId,
|
|
operationId: operationId ?? this.operationId,
|
|
);
|
|
}
|
|
|
|
@override
|
|
List<Object?> get props => [
|
|
id,
|
|
createdAt,
|
|
type,
|
|
expiration,
|
|
providerId,
|
|
operationId,
|
|
];
|
|
|
|
factory EnergyOperationModel.fromMap(Map<String, dynamic> map) {
|
|
return EnergyOperationModel(
|
|
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']),
|
|
providerId: map['provider_id'],
|
|
operationId: map['operation_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(),
|
|
'provider_id': providerId,
|
|
'operation_id': operationId,
|
|
};
|
|
}
|
|
}
|