68 lines
1.9 KiB
Dart
68 lines
1.9 KiB
Dart
/// Real User Profile Model (Student / Guardian / Teacher)
|
|
class UserModel {
|
|
final int id;
|
|
final String uuid;
|
|
final String name;
|
|
final String phone;
|
|
final String role;
|
|
final String? nationalId;
|
|
final String? gradeLevel;
|
|
final String? stream;
|
|
final double? readinessScore;
|
|
final int? schoolId;
|
|
final bool isCompleted;
|
|
|
|
UserModel({
|
|
required this.id,
|
|
required this.uuid,
|
|
required this.name,
|
|
required this.phone,
|
|
required this.role,
|
|
this.nationalId,
|
|
this.gradeLevel,
|
|
this.stream,
|
|
this.readinessScore,
|
|
this.schoolId,
|
|
this.isCompleted = true,
|
|
});
|
|
|
|
factory UserModel.fromJson(Map<String, dynamic> json) {
|
|
return UserModel(
|
|
id: json['id'] is int ? json['id'] : int.tryParse(json['id']?.toString() ?? '0') ?? 0,
|
|
uuid: json['uuid']?.toString() ?? '',
|
|
name: json['name']?.toString() ?? json['full_name']?.toString() ?? 'مستخدم صَقِل',
|
|
phone: json['phone']?.toString() ?? '',
|
|
role: json['role']?.toString() ?? 'student',
|
|
nationalId: json['national_id']?.toString(),
|
|
gradeLevel: json['grade_level']?.toString(),
|
|
stream: json['stream']?.toString(),
|
|
readinessScore: json['readiness_score'] != null
|
|
? double.tryParse(json['readiness_score'].toString())
|
|
: null,
|
|
schoolId: json['school_id'] != null
|
|
? int.tryParse(json['school_id'].toString())
|
|
: null,
|
|
isCompleted: json['is_completed'] ?? true,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'uuid': uuid,
|
|
'name': name,
|
|
'phone': phone,
|
|
'role': role,
|
|
'national_id': nationalId,
|
|
'grade_level': gradeLevel,
|
|
'stream': stream,
|
|
'readiness_score': readinessScore,
|
|
'school_id': schoolId,
|
|
'is_completed': isCompleted,
|
|
};
|
|
}
|
|
|
|
bool get isStudent => role == 'student';
|
|
bool get isGuardian => role == 'guardian';
|
|
}
|