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 gestoreId; final String? serviceId; const EnergyServiceModel({ this.id, this.createdAt, required this.type, required this.expiration, required this.gestoreId, this.serviceId, }); EnergyServiceModel copyWith({ String? id, DateTime? createdAt, EnergyType? type, DateTime? expiration, String? gestoreId, String? serviceId, }) { return EnergyServiceModel( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, type: type ?? this.type, expiration: expiration ?? this.expiration, gestoreId: gestoreId ?? this.gestoreId, serviceId: serviceId ?? this.serviceId, ); } @override List get props => [ id, createdAt, type, expiration, gestoreId, 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']), gestoreId: map['gestore_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(), 'gestore_id': gestoreId, 'service_id': serviceId, }; } }