import 'package:equatable/equatable.dart';

class PendingExpensesResponse extends Equatable {
  final bool success;
  final String message;
  final PendingExpensesData? data;
  final dynamic errors;
  final int statusCode;
  final String timestamp;

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

  factory PendingExpensesResponse.fromJson(Map<String, dynamic> json) {
    return PendingExpensesResponse(
      success: json['success'] ?? false,
      message: json['message'] ?? '',
      data: json['data'] != null
          ? PendingExpensesData.fromJson(json['data'])
          : null,
      errors: json['errors'],
      statusCode: json['statusCode'] ?? 0,
      timestamp: json['timestamp'] ?? '',
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'success': success,
      'message': message,
      'data': data?.toJson(),
      'errors': errors,
      'statusCode': statusCode,
      'timestamp': timestamp,
    };
  }

  PendingExpensesResponse copyWith({
    bool? success,
    String? message,
    PendingExpensesData? data,
    dynamic errors,
    int? statusCode,
    String? timestamp,
  }) {
    return PendingExpensesResponse(
      success: success ?? this.success,
      message: message ?? this.message,
      data: data ?? this.data,
      errors: errors ?? this.errors,
      statusCode: statusCode ?? this.statusCode,
      timestamp: timestamp ?? this.timestamp,
    );
  }

  @override
  List<Object?> get props => [success, message, data, errors, statusCode, timestamp];
}

class PendingExpensesData extends Equatable {
  final ExpenseStatus draft;
  final ExpenseStatus reviewPending;
  final ExpenseStatus approvePending;
  final ExpenseStatus processPending;
  final ExpenseStatus submited;
  final double totalAmount;

  const PendingExpensesData({
    required this.draft,
    required this.reviewPending,
    required this.approvePending,
    required this.processPending,
    required this.submited,
    required this.totalAmount,
  });

  factory PendingExpensesData.fromJson(Map<String, dynamic> json) {
    return PendingExpensesData(
      draft: ExpenseStatus.fromJson(json['draft']),
      reviewPending: ExpenseStatus.fromJson(json['reviewPending']),
      approvePending: ExpenseStatus.fromJson(json['approvePending']),
      processPending: ExpenseStatus.fromJson(json['processPending']),
      submited: ExpenseStatus.fromJson(json['submited']),
      totalAmount: (json['totalAmount'] ?? 0).toDouble(),
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'draft': draft.toJson(),
      'reviewPending': reviewPending.toJson(),
      'approvePending': approvePending.toJson(),
      'processPending': processPending.toJson(),
      'submited': submited.toJson(),
      'totalAmount': totalAmount,
    };
  }

  PendingExpensesData copyWith({
    ExpenseStatus? draft,
    ExpenseStatus? reviewPending,
    ExpenseStatus? approvePending,
    ExpenseStatus? processPending,
    ExpenseStatus? submited,
    double? totalAmount,
  }) {
    return PendingExpensesData(
      draft: draft ?? this.draft,
      reviewPending: reviewPending ?? this.reviewPending,
      approvePending: approvePending ?? this.approvePending,
      processPending: processPending ?? this.processPending,
      submited: submited ?? this.submited,
      totalAmount: totalAmount ?? this.totalAmount,
    );
  }

  @override
  List<Object?> get props => [
        draft,
        reviewPending,
        approvePending,
        processPending,
        submited,
        totalAmount,
      ];
}

class ExpenseStatus extends Equatable {
  final int count;
  final double totalAmount;

  const ExpenseStatus({
    required this.count,
    required this.totalAmount,
  });

  factory ExpenseStatus.fromJson(Map<String, dynamic> json) {
    return ExpenseStatus(
      count: json['count'] ?? 0,
      totalAmount: (json['totalAmount'] ?? 0).toDouble(),
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'count': count,
      'totalAmount': totalAmount,
    };
  }

  ExpenseStatus copyWith({
    int? count,
    double? totalAmount,
  }) {
    return ExpenseStatus(
      count: count ?? this.count,
      totalAmount: totalAmount ?? this.totalAmount,
    );
  }

  @override
  List<Object?> get props => [count, totalAmount];
}
