handleCommand method

  1. @override
Future<List<Event>> handleCommand(
  1. InvoiceState currentState,
  2. Command command
)

Handle a command and generate events This is the core method for command processing

Implementation

@override
Future<List<Event>> handleCommand(InvoiceState currentState, Command command) async {
  return switch (command.runtimeType) {
    CreateInvoiceCommand => _handleCreateInvoice(currentState, command as CreateInvoiceCommand),
    MarkInvoicePaidCommand => _handleMarkInvoicePaid(currentState, command as MarkInvoicePaidCommand),
    CancelInvoiceCommand => _handleCancelInvoice(currentState, command as CancelInvoiceCommand),
    ExpireInvoiceCommand => _handleExpireInvoice(currentState, command as ExpireInvoiceCommand),
    _ => throw ArgumentError('Unknown command type: ${command.runtimeType}'),
  };
}