Files
flux/lib/features/master_data/staff/models/staff_member_model.dart
Mark M2 Macbook 90bd5ecacf rework-onboarding (#7)
Onboarding completato, ora super rapido e top

Reviewed-on: http://catelliub.zapto.org:3000/brontomark/flux/pulls/7
Co-authored-by: Mark M2 Macbook <marco@catelli.it>
Co-committed-by: Mark M2 Macbook <marco@catelli.it>
2026-04-22 11:06:02 +02:00

120 lines
2.8 KiB
Dart

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 userId;
final String name;
final String? email;
final String? phoneNumber;
final String? jobTitle;
final SystemRole systemRole;
final bool isActive;
const StaffMemberModel({
this.id,
required this.companyId,
required this.userId,
required this.name,
this.email,
this.phoneNumber,
this.jobTitle,
this.systemRole = SystemRole.user,
this.isActive = true,
});
StaffMemberModel copyWith({
String? id,
String? companyId,
String? userId,
String? name,
String? surname,
String? email,
String? phoneNumber,
String? jobTitle,
SystemRole? systemRole,
bool? isActive,
}) {
return StaffMemberModel(
id: id ?? this.id,
companyId: companyId ?? this.companyId,
userId: userId ?? this.userId,
name: name ?? this.name,
email: email ?? this.email,
phoneNumber: phoneNumber ?? this.phoneNumber,
jobTitle: jobTitle ?? this.jobTitle,
systemRole: systemRole ?? this.systemRole,
isActive: isActive ?? this.isActive,
);
}
factory StaffMemberModel.empty() {
return const StaffMemberModel(
companyId: '',
userId: '',
name: '',
email: '',
phoneNumber: '',
jobTitle: '',
systemRole: SystemRole.user,
isActive: true,
);
}
factory StaffMemberModel.fromMap(Map<String, dynamic> map) {
return StaffMemberModel(
id: map['id'] as String?,
companyId: map['company_id'] ?? '',
userId: map['user_id'] ?? '',
name: map['name'] ?? '',
email: map['email'] as String?,
phoneNumber: map['phone_number'] as String?,
jobTitle: map['job_title'] as String?,
systemRole: SystemRole.fromString(map['system_role']),
isActive: map['is_active'] ?? true,
);
}
Map<String, dynamic> toMap() {
return {
if (id != null) 'id': id,
'company_id': companyId,
'user_id': userId,
'name': name,
if (email != null) 'email': email,
if (phoneNumber != null) 'phone_number': phoneNumber,
if (jobTitle != null) 'job_title': jobTitle,
'system_role': systemRole.name, // Trasforma SystemRole.admin in 'admin'
'is_active': isActive,
};
}
@override
List<Object?> get props => [
id,
companyId,
userId,
name,
email,
phoneNumber,
jobTitle,
systemRole,
isActive,
];
}