using System;
using System.Threading;
using System.Threading.Tasks;
namespace Svrnty.CQRS.Events.Abstractions.Sagas;
///
/// Orchestrates saga execution with compensation logic.
///
public interface ISagaOrchestrator
{
///
/// Start a new saga instance.
///
/// The saga type.
/// Correlation ID for this saga.
/// Optional initial saga data.
/// Cancellation token.
/// The saga ID.
Task StartSagaAsync(
string correlationId,
ISagaData? initialData = null,
CancellationToken cancellationToken = default)
where TSaga : ISaga;
///
/// Resume a paused saga.
///
/// The saga ID to resume.
/// Cancellation token.
Task ResumeSagaAsync(string sagaId, CancellationToken cancellationToken = default);
///
/// Cancel a running saga (triggers compensation).
///
/// The saga ID to cancel.
/// Cancellation token.
Task CancelSagaAsync(string sagaId, CancellationToken cancellationToken = default);
///
/// Get saga status.
///
/// The saga ID.
/// Cancellation token.
/// Saga status information.
Task GetStatusAsync(string sagaId, CancellationToken cancellationToken = default);
}
///
/// Status information for a saga instance.
///
public sealed record SagaStatus
{
///
/// Saga instance ID.
///
public required string SagaId { get; init; }
///
/// Correlation ID.
///
public required string CorrelationId { get; init; }
///
/// Saga type name.
///
public required string SagaName { get; init; }
///
/// Current state.
///
public SagaState State { get; init; }
///
/// Current step index being executed.
///
public int CurrentStep { get; init; }
///
/// Total number of steps.
///
public int TotalSteps { get; init; }
///
/// When the saga started.
///
public DateTimeOffset StartedAt { get; init; }
///
/// When the saga last updated.
///
public DateTimeOffset LastUpdated { get; init; }
///
/// When the saga completed (if completed).
///
public DateTimeOffset? CompletedAt { get; init; }
///
/// Error message (if failed).
///
public string? ErrorMessage { get; init; }
///
/// Saga data.
///
public System.Collections.Generic.IDictionary? Data { get; init; }
}