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 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 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) { final customers = json .map((e) => Customer.fromJson(e as Map)) .toList(); return CustomerListResponse( data: customers, total: customers.length, page: 1, pageSize: customers.length, ); } return CustomerListResponse.fromJson(json as Map); } factory CustomerListResponse.fromJson(Map json) => CustomerListResponse( data: ((json['data'] ?? const []) as List) .map((e) => Customer.fromJson(e as Map)) .toList(), total: json['total'] as int? ?? ((json['data'] as List?)?.length ?? 0), page: json['page'] as int? ?? 1, pageSize: json['pageSize'] as int? ?? 20, ); }