/// 报表汇总数据
class ReportSummary {
  final double totalAmount;
  final int totalCount;
  final int transferredCount; // 已转报销笔数
  final double transferredAmount; // 已转报销金额
  final double approvedAmount; // 核准金额

  const ReportSummary({
    this.totalAmount = 0,
    this.totalCount = 0,
    this.transferredCount = 0,
    this.transferredAmount = 0,
    this.approvedAmount = 0,
  });

  factory ReportSummary.fromJson(Map<String, dynamic> json) {
    return ReportSummary(
      totalAmount: (json['totalAmount'] as num?)?.toDouble() ?? 0,
      totalCount: json['totalCount'] as int? ?? 0,
      transferredCount: json['transferredCount'] as int? ?? 0,
      transferredAmount: (json['transferredAmount'] as num?)?.toDouble() ?? 0,
      approvedAmount: (json['approvedAmount'] as num?)?.toDouble() ?? 0,
    );
  }
}

/// 月度报表数据
class ReportMonthlyItem {
  final int month;
  final double amount;
  final double transferredAmount; // 当月已转报销金额
  final double approvedAmount; // 当月核准金额
  final int count;

  const ReportMonthlyItem({
    this.month = 0,
    this.amount = 0,
    this.transferredAmount = 0,
    this.approvedAmount = 0,
    this.count = 0,
  });

  factory ReportMonthlyItem.fromJson(Map<String, dynamic> json) {
    return ReportMonthlyItem(
      month: json['month'] as int? ?? 0,
      amount: (json['amount'] as num?)?.toDouble() ?? 0,
      transferredAmount: (json['transferredAmount'] as num?)?.toDouble() ?? 0,
      approvedAmount: (json['approvedAmount'] as num?)?.toDouble() ?? 0,
      count: json['count'] as int? ?? 0,
    );
  }
}

/// 报表明细项
class ReportDetailItem {
  final String billNo;
  final String? billDate;
  final double amount;
  final double approvedAmount; // 核准金额
  final bool isTransferred;
  final String reason;

  const ReportDetailItem({
    this.billNo = '',
    this.billDate,
    this.amount = 0,
    this.approvedAmount = 0,
    this.isTransferred = false,
    this.reason = '',
  });

  factory ReportDetailItem.fromJson(Map<String, dynamic> json) {
    return ReportDetailItem(
      billNo: json['billNo'] as String? ?? '',
      billDate: json['billDate'] as String?,
      amount: (json['amount'] as num?)?.toDouble() ?? 0,
      approvedAmount: (json['approvedAmount'] as num?)?.toDouble() ?? 0,
      isTransferred: json['isTransferred'] as bool? ?? false,
      reason: json['reason'] as String? ?? '',
    );
  }
}

/// 报表完整数据
class ReportData {
  final ReportSummary summary;
  final List<ReportMonthlyItem> monthly;
  final List<ReportDetailItem> details;

  const ReportData({
    this.summary = const ReportSummary(),
    this.monthly = const [],
    this.details = const [],
  });

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

/// 下属报销金额对比数据
class SubordinateReportItem {
  final String usr;
  final String usrName;
  final double amount;
  final int cnt;

  const SubordinateReportItem({
    this.usr = '',
    this.usrName = '',
    this.amount = 0,
    this.cnt = 0,
  });

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