104 lines
3.0 KiB
Dart
104 lines
3.0 KiB
Dart
class AuthSessionModel {
|
|
final String accessToken;
|
|
final String? refreshToken;
|
|
final int? expires;
|
|
final String userId;
|
|
final String firstName;
|
|
final String lastName;
|
|
final String email;
|
|
final String? roleName;
|
|
|
|
const AuthSessionModel({
|
|
required this.accessToken,
|
|
this.refreshToken,
|
|
this.expires,
|
|
required this.userId,
|
|
required this.firstName,
|
|
required this.lastName,
|
|
required this.email,
|
|
this.roleName,
|
|
});
|
|
|
|
String get fullName {
|
|
final name = '$firstName $lastName'.trim();
|
|
return name.isNotEmpty ? name : 'Dr. Luis A. Castro Sosa';
|
|
}
|
|
|
|
/// Indica si el usuario actual tiene rol de Secretaria, Asistente o Recepción
|
|
bool get isSecretary {
|
|
final normalized = (roleName ?? '').trim().toLowerCase();
|
|
return normalized.contains('secretari') ||
|
|
normalized.contains('asistent') ||
|
|
normalized.contains('recepc');
|
|
}
|
|
|
|
/// Indica si el usuario actual es Doctor o Administrador
|
|
bool get isDoctorOrAdmin => !isSecretary;
|
|
|
|
AuthSessionModel copyWith({
|
|
String? accessToken,
|
|
String? refreshToken,
|
|
int? expires,
|
|
String? userId,
|
|
String? firstName,
|
|
String? lastName,
|
|
String? email,
|
|
String? roleName,
|
|
}) {
|
|
return AuthSessionModel(
|
|
accessToken: accessToken ?? this.accessToken,
|
|
refreshToken: refreshToken ?? this.refreshToken,
|
|
expires: expires ?? this.expires,
|
|
userId: userId ?? this.userId,
|
|
firstName: firstName ?? this.firstName,
|
|
lastName: lastName ?? this.lastName,
|
|
email: email ?? this.email,
|
|
roleName: roleName ?? this.roleName,
|
|
);
|
|
}
|
|
|
|
factory AuthSessionModel.fromLoginAndUser({
|
|
required Map<String, dynamic> loginData,
|
|
required Map<String, dynamic> userData,
|
|
}) {
|
|
return AuthSessionModel(
|
|
accessToken: loginData['access_token'] as String? ?? '',
|
|
refreshToken: loginData['refresh_token'] as String?,
|
|
expires: loginData['expires'] as int?,
|
|
userId: userData['id'] as String? ?? '',
|
|
firstName: userData['first_name'] as String? ?? '',
|
|
lastName: userData['last_name'] as String? ?? '',
|
|
email: userData['email'] as String? ?? '',
|
|
roleName: (userData['role'] is Map)
|
|
? userData['role']['name'] as String?
|
|
: userData['role']?.toString(),
|
|
);
|
|
}
|
|
|
|
factory AuthSessionModel.fromJson(Map<String, dynamic> json) {
|
|
return AuthSessionModel(
|
|
accessToken: json['access_token'] as String? ?? '',
|
|
refreshToken: json['refresh_token'] as String?,
|
|
expires: json['expires'] as int?,
|
|
userId: json['user_id'] as String? ?? '',
|
|
firstName: json['first_name'] as String? ?? '',
|
|
lastName: json['last_name'] as String? ?? '',
|
|
email: json['email'] as String? ?? '',
|
|
roleName: json['role_name'] as String?,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'access_token': accessToken,
|
|
'refresh_token': refreshToken,
|
|
'expires': expires,
|
|
'user_id': userId,
|
|
'first_name': firstName,
|
|
'last_name': lastName,
|
|
'email': email,
|
|
'role_name': roleName,
|
|
};
|
|
}
|
|
}
|