part of 'transaction_bloc.dart';

final class TransactionState extends Equatable {
  final double globalTotal;
  final Map<String, double> accountsTotals;
  
  final List<Transaction> transactions;
  final List<TransactionLine> transactionsLines;
  final List<TransactionLine> transactionsLinesFiltered;
  final Category? categoryFilter;

  final TransactionDate transactionDate;
  final TransactionCategory transactionCategory;
  final TransactionDescription transactionDescription;
  final TransactionAccount transactionAccount;
  final TransactionValue transactionValue;
  final bool isValid;
  final bool showAddDialog;

  final Transaction? currentTransaction;

  const TransactionState({
    this.globalTotal = 0,
    this.accountsTotals = const <String, double>{},
    this.transactions = const [],
    this.transactionsLines = const [],
    this.transactionsLinesFiltered = const [],
    this.transactionDate = const TransactionDate.pure(),
    this.transactionCategory = const TransactionCategory.pure(),
    this.transactionDescription = const TransactionDescription.pure(),
    this.transactionAccount = const TransactionAccount.pure(),
    this.transactionValue = const TransactionValue.pure(),
    this.isValid = false,
    this.showAddDialog = false,
    this.currentTransaction,
    this.categoryFilter,
  });

  TransactionState copyWith({
    double? globalTotal,
    Map<String, double>? accountsTotals,
    List<Transaction>? transactions,
    List<TransactionLine>? transactionsLines,
    List<TransactionLine>? transactionsLinesFiltered,
    TransactionDate? transactionDate,
    TransactionCategory? transactionCategory,
    TransactionDescription? transactionDescription,
    TransactionAccount? transactionAccount,
    TransactionValue? transactionValue,
    bool? isValid,
    bool? showAddDialog,
    Transaction? currentTransaction,
    Category? categoryFilter,
  }) {
    return TransactionState(
      globalTotal: globalTotal ?? this.globalTotal,
      accountsTotals: accountsTotals ?? this.accountsTotals,
      transactions: transactions ?? this.transactions,
      transactionsLines: transactionsLines ?? this.transactionsLines,
      transactionsLinesFiltered: transactionsLinesFiltered ?? this.transactionsLinesFiltered,
      transactionDate: transactionDate ?? this.transactionDate,
      transactionCategory: transactionCategory ?? this.transactionCategory,
      transactionDescription: transactionDescription ?? this.transactionDescription,
      transactionAccount: transactionAccount ?? this.transactionAccount,
      transactionValue: transactionValue ?? this.transactionValue,
      isValid: isValid ?? this.isValid,
      showAddDialog: showAddDialog ?? this.showAddDialog,
      currentTransaction: currentTransaction ?? this.currentTransaction,
      categoryFilter: categoryFilter,
    );
  }

  @override
  List<Object?> get props => [
    transactionDate,
    transactionCategory,
    transactionDescription,
    transactionAccount,
    transactionValue,
    isValid,
    showAddDialog,
    currentTransaction,
    categoryFilter,
  ];
  
}