class Vehicle { final String id; final String make; final String model; final int year; final String licensePlate; final double dailyRate; final String status; final String category; final List photos; final int? mileage; final int? seats; final String? transmission; final String? fuelType; final String? color; final bool isPublished; const Vehicle({ required this.id, required this.make, required this.model, required this.year, required this.licensePlate, required this.dailyRate, required this.status, required this.category, required this.photos, this.mileage, this.seats, this.transmission, this.fuelType, this.color, required this.isPublished, }); String get displayName => '$year $make $model'; String? get primaryPhoto => photos.isNotEmpty ? photos.first : null; factory Vehicle.fromJson(Map json) => Vehicle( id: json['id'] as String, make: json['make'] as String, model: json['model'] as String, year: json['year'] as int, licensePlate: json['licensePlate'] as String, dailyRate: (json['dailyRate'] as num).toDouble(), status: json['status'] as String? ?? 'AVAILABLE', category: json['category'] as String? ?? 'ECONOMY', photos: (json['photos'] as List?) ?.map((e) => e as String) .toList() ?? [], mileage: json['mileage'] as int?, seats: json['seats'] as int?, transmission: json['transmission'] as String?, fuelType: json['fuelType'] as String?, color: json['color'] as String?, isPublished: json['isPublished'] as bool? ?? false, ); } class VehicleListResponse { final List data; final int total; final int page; final int pageSize; const VehicleListResponse({ required this.data, required this.total, required this.page, required this.pageSize, }); factory VehicleListResponse.fromApi(dynamic json) { if (json is List) { final vehicles = json .map((e) => Vehicle.fromJson(e as Map)) .toList(); return VehicleListResponse( data: vehicles, total: vehicles.length, page: 1, pageSize: vehicles.length, ); } return VehicleListResponse.fromJson(json as Map); } factory VehicleListResponse.fromJson(Map json) => VehicleListResponse( data: ((json['data'] ?? const []) as List) .map((e) => Vehicle.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, ); }