class ExpenseReportResponse {
  final bool success;
  final String message;
  final List<ExpenseReportData> data;
  final dynamic errors;
  final int statusCode;
  final DateTime timestamp;

  ExpenseReportResponse({
    required this.success,
    required this.message,
    required this.data,
    this.errors,
    required this.statusCode,
    required this.timestamp,
  });

  factory ExpenseReportResponse.fromJson(Map<String, dynamic> json) {
    return ExpenseReportResponse(
      success: json['success'] ?? false,
      message: json['message'] ?? '',
      data: json['data'] != null
          ? List<ExpenseReportData>.from(
              json['data'].map((x) => ExpenseReportData.fromJson(x)))
          : [],
      errors: json['errors'],
      statusCode: json['statusCode'] ?? 0,
      timestamp: DateTime.parse(json['timestamp']),
    );
  }

  Map<String, dynamic> toJson() => {
        'success': success,
        'message': message,
        'data': data.map((x) => x.toJson()).toList(),
        'errors': errors,
        'statusCode': statusCode,
        'timestamp': timestamp.toIso8601String(),
      };
}

class ExpenseReportData {
  final String monthName;
  final int year;
  final double total;
  final int count;

  ExpenseReportData({
    required this.monthName,
    required this.year,
    required this.total,
    required this.count,
  });

  factory ExpenseReportData.fromJson(Map<String, dynamic> json) {
    return ExpenseReportData(
      monthName: json['monthName'] ?? '',
      year: json['year'] ?? 0,
      total: json['total'] != null
          ? (json['total'] is int
              ? (json['total'] as int).toDouble()
              : json['total'] as double)
          : 0.0,
      count: json['count'] ?? 0,
    );
  }

  Map<String, dynamic> toJson() => {
        'monthName': monthName,
        'year': year,
        'total': total,
        'count': count,
      };
}
