aiuto
This commit is contained in:
@@ -1,47 +1,101 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flux/core/utils/string_extensions.dart'; // Assicurati che il percorso sia corretto
|
||||
|
||||
// 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 name;
|
||||
final String email;
|
||||
final String phone;
|
||||
final bool isActive;
|
||||
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.name,
|
||||
this.email = '',
|
||||
this.phone = '',
|
||||
this.isActive = true,
|
||||
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<String, dynamic> map) {
|
||||
return StaffMemberModel(
|
||||
id: map['id'],
|
||||
// Applichiamo il tuo myFormat per visualizzare i nomi correttamente
|
||||
name: (map['name'] as String).myFormat(),
|
||||
// L'email la teniamo lowercase per standard tecnico
|
||||
email: (map['email'] as String? ?? '').toLowerCase().trim(),
|
||||
phone: (map['phone'] as String? ?? '').trim(),
|
||||
isActive: map['is_active'] ?? true,
|
||||
companyId: map['company_id'],
|
||||
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<String, dynamic> toMap() {
|
||||
return {
|
||||
if (id != null) 'id': id,
|
||||
'name': name.toLowerCase().trim(), // Salviamo pulito per le query
|
||||
'email': email.toLowerCase().trim(),
|
||||
'phone': phone.trim(),
|
||||
'is_active': isActive,
|
||||
'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<Object?> get props => [id, name, email, phone, isActive, companyId];
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
companyId,
|
||||
storeId,
|
||||
userId,
|
||||
name,
|
||||
surname,
|
||||
jobTitle,
|
||||
systemRole,
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user