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; final String providerId; final String? serviceId; const EnergyServiceModel({ this.id, this.createdAt, required this.type, required this.expiration, required this.providerId, this.serviceId, }); EnergyServiceModel copyWith({ String? id, DateTime? createdAt, EnergyType? type, DateTime? expiration, String? providerId, String? serviceId, }) { return EnergyServiceModel( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, type: type ?? this.type, expiration: expiration ?? this.expiration, providerId: providerId ?? this.providerId, serviceId: serviceId ?? this.serviceId, ); } @override List get props => [ id, createdAt, type, expiration, providerId, serviceId, ]; factory EnergyServiceModel.fromMap(Map 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']), providerId: map['provider_id'], serviceId: map['service_id'], ); } Map toMap() { return { if (id != null) 'id': id, 'type': type.name, // .name trasforma l'enum in 'luce' o 'gas' 'expiration': expiration.toIso8601String(), 'provider_id': providerId, 'service_id': serviceId, }; } }