using System.Threading;
using Svrnty.CQRS.Events.Abstractions.EventStore;
using Svrnty.CQRS.Events.Abstractions.Context;
using System.Threading.Tasks;
namespace Svrnty.CQRS.Events.Abstractions.EventHandlers;
///
/// Command handler that can emit strongly-typed correlated events.
/// The framework automatically manages correlation IDs and event emission.
///
/// The command type to handle.
/// The result type returned by the command.
/// The base type or marker interface for events this command can emit.
public interface ICommandHandlerWithEvents
where TCommand : class
where TEvents : ICorrelatedEvent
{
///
/// Handle the command and emit events using the provided event context.
/// The framework will automatically assign correlation IDs and emit the events.
///
/// The command to handle.
/// Context for emitting events with automatic correlation ID management.
/// Cancellation token.
/// The command result.
Task HandleAsync(TCommand command, IEventContext eventContext, CancellationToken cancellationToken = default);
}
///
/// Command handler that emits events but returns no result.
///
/// The command type to handle.
/// The base type or marker interface for events this command can emit.
public interface ICommandHandlerWithEvents
where TCommand : class
where TEvents : ICorrelatedEvent
{
///
/// Handle the command and emit events using the provided event context.
/// The framework will automatically assign correlation IDs and emit the events.
///
/// The command to handle.
/// Context for emitting events with automatic correlation ID management.
/// Cancellation token.
Task HandleAsync(TCommand command, IEventContext eventContext, CancellationToken cancellationToken = default);
}
///
/// Command handler that emits events and returns the result with correlation ID.
/// Use this variant when you need to return the correlation ID to the caller (e.g., for multi-step workflows).
///
/// The command type to handle.
/// The result type returned by the command.
/// The base type or marker interface for events this command can emit.
public interface ICommandHandlerWithEventsAndCorrelation
where TCommand : class
where TEvents : ICorrelatedEvent
{
///
/// Handle the command and emit events using the provided event context.
/// The framework will automatically assign correlation IDs and emit the events.
/// Returns the result wrapped with the correlation ID for use in follow-up commands.
///
/// The command to handle.
/// Context for emitting events with automatic correlation ID management.
/// Cancellation token.
/// The command result wrapped with the correlation ID.
Task HandleAsync(TCommand command, IEventContext eventContext, CancellationToken cancellationToken = default);
}