You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
3.8 KiB
Dart

/// Raw API response model — mirrors the JSON returned by the verification endpoint.
///
/// Example JSON:
/// ```json
/// {
/// "success": true,
/// "statusMessage": "Authentication successful!",
/// "personInfo": {
/// "firstName": "ASIF",
/// "lastName": "EHTESHAM UL HAQ",
/// "fatherName": "RAZA EHTESHAM",
/// "grandfatherName": "MUHAMMAD",
/// "occupation": "Computer Science Specialist",
/// "gender": "1",
/// "sponsor": "",
/// "idNumber": "2257773628",
/// "birthDate": "1985-01-04",
/// "nationality": "304"
/// },
/// "error": {
/// "type": "",
/// "message": ""
/// }
/// }
/// ```
class AuthResponseModel {
final bool success;
final String statusMessage;
final PersonInfoResponse? personInfo;
final ErrorResponse? error;
const AuthResponseModel({
required this.success,
required this.statusMessage,
this.personInfo,
this.error,
});
factory AuthResponseModel.fromJson(Map<String, dynamic> json) {
return AuthResponseModel(
success: json['success'] as bool? ?? false,
statusMessage: json['statusMessage'] as String? ?? '',
personInfo: json['personInfo'] != null
? PersonInfoResponse.fromJson(
json['personInfo'] as Map<String, dynamic>)
: null,
error: json['error'] != null
? ErrorResponse.fromJson(json['error'] as Map<String, dynamic>)
: null,
);
}
Map<String, dynamic> toJson() => {
'success': success,
'statusMessage': statusMessage,
'personInfo': personInfo?.toJson(),
'error': error?.toJson(),
};
}
/// Sub-model for the person information section of the response.
class PersonInfoResponse {
final String firstName;
final String lastName;
final String fatherName;
final String grandfatherName;
final String occupation;
final String gender;
final String sponsor;
final String idNumber;
final String birthDate;
final String nationality;
const PersonInfoResponse({
required this.firstName,
required this.lastName,
required this.fatherName,
required this.grandfatherName,
required this.occupation,
required this.gender,
required this.sponsor,
required this.idNumber,
required this.birthDate,
required this.nationality,
});
factory PersonInfoResponse.fromJson(Map<String, dynamic> json) {
return PersonInfoResponse(
firstName: json['firstName'] as String? ?? '',
lastName: json['lastName'] as String? ?? '',
fatherName: json['fatherName'] as String? ?? '',
grandfatherName: json['grandfatherName'] as String? ?? '',
occupation: json['occupation'] as String? ?? '',
gender: json['gender'] as String? ?? '',
sponsor: json['sponsor'] as String? ?? '',
idNumber: json['idNumber'] as String? ?? '',
birthDate: json['birthDate'] as String? ?? '',
nationality: json['nationality'] as String? ?? '',
);
}
Map<String, dynamic> toJson() => {
'firstName': firstName,
'lastName': lastName,
'fatherName': fatherName,
'grandfatherName': grandfatherName,
'occupation': occupation,
'gender': gender,
'sponsor': sponsor,
'idNumber': idNumber,
'birthDate': birthDate,
'nationality': nationality,
};
}
/// Sub-model for the error section of the response.
class ErrorResponse {
final String type;
final String message;
const ErrorResponse({
required this.type,
required this.message,
});
factory ErrorResponse.fromJson(Map<String, dynamic> json) {
return ErrorResponse(
type: json['type'] as String? ?? '',
message: json['message'] as String? ?? '',
);
}
Map<String, dynamic> toJson() => {
'type': type,
'message': message,
};
bool get hasError => type.isNotEmpty || message.isNotEmpty;
}