86 lines
2.5 KiB
Dart
86 lines
2.5 KiB
Dart
class Customer {
|
|
final String id;
|
|
final String firstName;
|
|
final String lastName;
|
|
final String? email;
|
|
final String? phone;
|
|
final String licenseStatus;
|
|
final bool isFlagged;
|
|
final String? flagReason;
|
|
final DateTime? dateOfBirth;
|
|
final String? nationality;
|
|
final DateTime createdAt;
|
|
|
|
const Customer({
|
|
required this.id,
|
|
required this.firstName,
|
|
required this.lastName,
|
|
this.email,
|
|
this.phone,
|
|
required this.licenseStatus,
|
|
required this.isFlagged,
|
|
this.flagReason,
|
|
this.dateOfBirth,
|
|
this.nationality,
|
|
required this.createdAt,
|
|
});
|
|
|
|
String get fullName => '$firstName $lastName';
|
|
|
|
factory Customer.fromJson(Map<String, dynamic> json) => Customer(
|
|
id: json['id'] as String,
|
|
firstName: json['firstName'] as String,
|
|
lastName: json['lastName'] as String,
|
|
email: json['email'] as String?,
|
|
phone: json['phone'] as String?,
|
|
licenseStatus: json['licenseStatus'] as String? ?? 'PENDING',
|
|
isFlagged: json['isFlagged'] as bool? ?? false,
|
|
flagReason: json['flagReason'] as String?,
|
|
dateOfBirth: json['dateOfBirth'] != null
|
|
? DateTime.tryParse(json['dateOfBirth'] as String)
|
|
: null,
|
|
nationality: json['nationality'] as String?,
|
|
createdAt: DateTime.parse(
|
|
json['createdAt'] as String? ?? DateTime.now().toIso8601String()),
|
|
);
|
|
}
|
|
|
|
class CustomerListResponse {
|
|
final List<Customer> data;
|
|
final int total;
|
|
final int page;
|
|
final int pageSize;
|
|
|
|
const CustomerListResponse({
|
|
required this.data,
|
|
required this.total,
|
|
required this.page,
|
|
required this.pageSize,
|
|
});
|
|
|
|
factory CustomerListResponse.fromApi(dynamic json) {
|
|
if (json is List<dynamic>) {
|
|
final customers = json
|
|
.map((e) => Customer.fromJson(e as Map<String, dynamic>))
|
|
.toList();
|
|
return CustomerListResponse(
|
|
data: customers,
|
|
total: customers.length,
|
|
page: 1,
|
|
pageSize: customers.length,
|
|
);
|
|
}
|
|
return CustomerListResponse.fromJson(json as Map<String, dynamic>);
|
|
}
|
|
|
|
factory CustomerListResponse.fromJson(Map<String, dynamic> json) =>
|
|
CustomerListResponse(
|
|
data: ((json['data'] ?? const <dynamic>[]) as List<dynamic>)
|
|
.map((e) => Customer.fromJson(e as Map<String, dynamic>))
|
|
.toList(),
|
|
total: json['total'] as int? ?? ((json['data'] as List<dynamic>?)?.length ?? 0),
|
|
page: json['page'] as int? ?? 1,
|
|
pageSize: json['pageSize'] as int? ?? 20,
|
|
);
|
|
}
|