import 'package:equatable/equatable.dart'; // L'Enum magico e blindato per il sistema enum SystemRole { admin, manager, user; // Helper per convertire dal DB a Dart in sicurezza static SystemRole fromString(String? value) { return SystemRole.values.firstWhere( (e) => e.name == value, orElse: () => SystemRole.user, // Fallback paranoico al livello più basso ); } } class StaffMemberModel extends Equatable { final String? id; final String companyId; final String storeId; final String userId; final String name; final String surname; final String? jobTitle; // Testo libero! Il cliente ci scrive quello che vuole. final SystemRole systemRole; // ENUM! Il sistema non si frega. const StaffMemberModel({ this.id, required this.companyId, required this.storeId, required this.userId, required this.name, required this.surname, this.jobTitle, this.systemRole = SystemRole.user, // Sicurezza di default }); StaffMemberModel copyWith({ String? id, String? companyId, String? storeId, String? userId, String? name, String? surname, String? jobTitle, SystemRole? systemRole, }) { return StaffMemberModel( id: id ?? this.id, companyId: companyId ?? this.companyId, storeId: storeId ?? this.storeId, userId: userId ?? this.userId, name: name ?? this.name, surname: surname ?? this.surname, jobTitle: jobTitle ?? this.jobTitle, systemRole: systemRole ?? this.systemRole, ); } factory StaffMemberModel.fromMap(Map map) { return StaffMemberModel( id: map['id'] as String?, companyId: map['company_id'] ?? '', storeId: map['store_id'] ?? '', userId: map['user_id'] ?? '', name: map['name'] ?? '', surname: map['surname'] ?? '', jobTitle: map['job_title'] as String?, // Semplice stringa systemRole: SystemRole.fromString( map['system_role'], ), // Lettura tipizzata ); } Map toMap() { return { if (id != null) 'id': id, 'company_id': companyId, 'store_id': storeId, 'user_id': userId, 'name': name, 'surname': surname, if (jobTitle != null) 'job_title': jobTitle, 'system_role': systemRole.name, // Trasforma SystemRole.admin in 'admin' }; } @override List get props => [ id, companyId, storeId, userId, name, surname, jobTitle, systemRole, ]; }