/// 用车报表汇总
class VehicleReportSummary {
  final int totalTrips;
  final double totalMileage;
  final int notReturnedCount;
  final double totalCost;

  const VehicleReportSummary({
    this.totalTrips = 0,
    this.totalMileage = 0,
    this.notReturnedCount = 0,
    this.totalCost = 0,
  });

  factory VehicleReportSummary.fromJson(Map<String, dynamic> json) {
    return VehicleReportSummary(
      totalTrips: json['totalTrips'] as int? ?? 0,
      totalMileage: (json['totalMileage'] as num?)?.toDouble() ?? 0,
      notReturnedCount: json['notReturnedCount'] as int? ?? 0,
      totalCost: (json['totalCost'] as num?)?.toDouble() ?? 0,
    );
  }
}

/// 月度用车数据
class VehicleMonthlyItem {
  final int month;
  final int trips;
  final double cost;
  final double mileage;
  final int count;

  const VehicleMonthlyItem({
    this.month = 0,
    this.trips = 0,
    this.cost = 0,
    this.mileage = 0,
    this.count = 0,
  });

  factory VehicleMonthlyItem.fromJson(Map<String, dynamic> json) {
    return VehicleMonthlyItem(
      month: json['month'] as int? ?? 0,
      trips: json['trips'] as int? ?? 0,
      cost: (json['cost'] as num?)?.toDouble() ?? 0,
      mileage: (json['mileage'] as num?)?.toDouble() ?? 0,
      count: json['count'] as int? ?? 0,
    );
  }
}

/// 用车报表完整数据
class VehicleReportData {
  final VehicleReportSummary summary;
  final List<VehicleMonthlyItem> monthly;

  const VehicleReportData({
    this.summary = const VehicleReportSummary(),
    this.monthly = const [],
  });

  factory VehicleReportData.fromJson(Map<String, dynamic> json) {
    return VehicleReportData(
      summary: json['summary'] != null
          ? VehicleReportSummary.fromJson(
              json['summary'] as Map<String, dynamic>,
            )
          : const VehicleReportSummary(),
      monthly:
          (json['monthly'] as List<dynamic>?)
              ?.map(
                (e) => VehicleMonthlyItem.fromJson(e as Map<String, dynamic>),
              )
              .toList() ??
          [],
    );
  }
}

/// 下属用车对比数据
class VehicleSubordinateItem {
  final String usr;
  final String usrName;
  final int trips;
  final double cost;

  const VehicleSubordinateItem({
    this.usr = '',
    this.usrName = '',
    this.trips = 0,
    this.cost = 0,
  });

  factory VehicleSubordinateItem.fromJson(Map<String, dynamic> json) {
    return VehicleSubordinateItem(
      usr: json['usr'] as String? ?? '',
      usrName: json['usrName'] as String? ?? '',
      trips: json['trips'] as int? ?? 0,
      cost: (json['cost'] as num?)?.toDouble() ?? 0,
    );
  }
}

/// 用车报表明细
class VehicleReportDetailItem {
  final String billNo;
  final String? billDate;
  final String applicantName;
  final String licensePlate;
  final String originAdr;
  final String destAdr;
  final double mileage;
  final String reason;

  const VehicleReportDetailItem({
    this.billNo = '',
    this.billDate,
    this.applicantName = '',
    this.licensePlate = '',
    this.originAdr = '',
    this.destAdr = '',
    this.mileage = 0,
    this.reason = '',
  });

  factory VehicleReportDetailItem.fromJson(Map<String, dynamic> json) {
    return VehicleReportDetailItem(
      billNo: json['billNo'] as String? ?? '',
      billDate: json['billDate'] as String?,
      applicantName: json['applicantName'] as String? ?? '',
      licensePlate: json['licensePlate'] as String? ?? '',
      originAdr: json['originAdr'] as String? ?? '',
      destAdr: json['destAdr'] as String? ?? '',
      mileage: (json['mileage'] as num?)?.toDouble() ?? 0,
      reason: json['reason'] as String? ?? '',
    );
  }
}
