using System;
using System.Collections.Generic;
using Svrnty.CQRS.Sagas.Abstractions;
namespace Svrnty.CQRS.Sagas.Builders;
///
/// Implementation of the saga builder for defining saga steps.
///
/// The saga data type.
public class SagaBuilder : ISagaBuilder
where TData : class, ISagaData
{
private readonly List _steps = new();
///
/// Gets the defined steps.
///
public IReadOnlyList Steps => _steps.AsReadOnly();
///
public ISagaStepBuilder Step(string name)
{
return new LocalSagaStepBuilder(this, name, _steps.Count);
}
///
public ISagaRemoteStepBuilder SendCommand(string name)
where TCommand : class
{
return new RemoteSagaStepBuilder(this, name, _steps.Count);
}
///
public ISagaRemoteStepBuilder SendCommand(string name)
where TCommand : class
{
return new RemoteSagaStepBuilderWithResult(this, name, _steps.Count);
}
///
/// Adds a step definition to the builder.
///
/// The step definition to add.
internal void AddStep(SagaStepDefinition step)
{
_steps.Add(step);
}
}