import 'package:equatable/equatable.dart'; class Fine extends Equatable { final int id; final String scooterNumber; final String date; final String description; final double amount; final String amountPrint; final List photoUrls; final bool isPaid; const Fine({ required this.id, required this.scooterNumber, required this.date, required this.description, required this.amount, required this.amountPrint, required this.photoUrls, required this.isPaid, }); factory Fine.fromJson(Map json, {String? scooterNumber}) { final List filesJson = json['files'] ?? []; final List photos = filesJson .map((file) => file['path'] as String? ?? file['filename'] as String? ?? '') .where((path) => path.isNotEmpty) .toList(); // Форматирование даты из createdAt (2026-08-07T09:15:26.565Z -> 07-08-2026) String formattedDate = ''; if (json['createdAt'] != null) { final parsedDate = DateTime.tryParse(json['createdAt'].toString()); if (parsedDate != null) { final day = parsedDate.day.toString().padLeft(2, '0'); final month = parsedDate.month.toString().padLeft(2, '0'); final year = parsedDate.year; formattedDate = '$day-$month-$year'; } } return Fine( id: json['id'] as int? ?? 0, scooterNumber: scooterNumber ?? '', date: formattedDate, description: json['description'] as String? ?? '', amount: (json['value'] as num?)?.toDouble() ?? 0.0, amountPrint: json['valuePrint'] as String? ?? '0,00 BYN', photoUrls: photos, isPaid: json['isPaid'] as bool? ?? false, ); } Map toJson() { return { 'id': id, 'description': description, 'value': amount, 'valuePrint': amountPrint, 'isPaid': isPaid, }; } @override List get props => [ id, scooterNumber, date, description, amount, amountPrint, photoUrls, isPaid, ]; }