class ReportSummary {
  final int totalReservations;
  final double rentalRevenue;
  final double totalPaid;
  final double totalOutstanding;
  final List<ReportItem> items;

  const ReportSummary({
    required this.totalReservations,
    required this.rentalRevenue,
    required this.totalPaid,
    required this.totalOutstanding,
    required this.items,
  });

  factory ReportSummary.fromJson(Map<String, dynamic> json) => ReportSummary(
        totalReservations: json['totalReservations'] as int? ?? 0,
        rentalRevenue: (json['rentalRevenue'] as num?)?.toDouble() ?? 0,
        totalPaid: (json['totalPaid'] as num?)?.toDouble() ?? 0,
        totalOutstanding:
            (json['totalOutstanding'] as num?)?.toDouble() ?? 0,
        items: (json['reservations'] as List<dynamic>? ?? [])
            .map((e) => ReportItem.fromJson(e as Map<String, dynamic>))
            .toList(),
      );
}

class ReportItem {
  final String id;
  final String? customerName;
  final String? vehicleName;
  final DateTime startDate;
  final DateTime endDate;
  final double totalAmount;
  final String status;
  final String paymentStatus;
  final String? source;

  const ReportItem({
    required this.id,
    this.customerName,
    this.vehicleName,
    required this.startDate,
    required this.endDate,
    required this.totalAmount,
    required this.status,
    required this.paymentStatus,
    this.source,
  });

  factory ReportItem.fromJson(Map<String, dynamic> json) => ReportItem(
        id: json['id'] as String,
        customerName: json['customerName'] as String?,
        vehicleName: json['vehicleName'] as String?,
        startDate: DateTime.parse(json['startDate'] as String),
        endDate: DateTime.parse(json['endDate'] as String),
        totalAmount: (json['totalAmount'] as num?)?.toDouble() ?? 0,
        status: json['status'] as String? ?? '',
        paymentStatus: json['paymentStatus'] as String? ?? '',
        source: json['source'] as String?,
      );
}
