enum MaintenanceType { cleaning('Nettoyage'), repair('Réparation'), inspection('Inspection'), upgrade('Amélioration'), other('Autre'); final String displayName; const MaintenanceType(this.displayName); static MaintenanceType fromString(String value) { return MaintenanceType.values.firstWhere( (type) => type.name == value, orElse: () => MaintenanceType.other, ); } } class MaintenanceEntry { final String id; final String weaponId; final MaintenanceType type; final String description; final DateTime date; final int? roundsSinceLastMaintenance; MaintenanceEntry({ required this.id, required this.weaponId, required this.type, required this.description, required this.date, this.roundsSinceLastMaintenance, }); Map toMap() { return { 'id': id, 'weapon_id': weaponId, 'type': type.name, 'description': description, 'date': date.toIso8601String(), 'rounds_since_last': roundsSinceLastMaintenance, }; } factory MaintenanceEntry.fromMap(Map map) { return MaintenanceEntry( id: map['id'] as String, weaponId: map['weapon_id'] as String, type: MaintenanceType.fromString(map['type'] as String), description: map['description'] as String, date: DateTime.parse(map['date'] as String), roundsSinceLastMaintenance: map['rounds_since_last'] as int?, ); } }