using System.Threading;
using System.Threading.Tasks;
namespace RudderSdk.Core;
/// Session of a scenario quest node.
public sealed class QuestSession
{
internal QuestSession(ScenarioNodeContext context) => Context = context;
/// Underlying node context.
public ScenarioNodeContext Context { get; }
/// Node id.
public string Id => Context.NodeId;
/// Reads a typed value from the node data.
public T Get(string key, T defaultValue = default!) => Context.Get(key, defaultValue);
/// Adds progress to one of the node's counters.
public Task AddProgressAsync(string counterKey, long amount, CancellationToken cancellationToken = default) => Context.AddProgressAsync(counterKey, amount, cancellationToken);
/// Adds progress to one of the node's counters (fire-and-forget).
public void AddProgress(string counterKey, long amount) => _ = AddProgressAsync(counterKey, amount);
/// Advances the run through the onComplete handle.
public Task CompleteAsync(CancellationToken cancellationToken = default) => Context.CompleteAsync("onComplete", cancellationToken);
/// Advances the run through the onComplete handle (fire-and-forget).
public void Complete() => Context.Complete("onComplete");
/// Advances the run through the onFail handle.
public Task FailAsync(CancellationToken cancellationToken = default) => Context.CompleteAsync("onFail", cancellationToken);
/// Advances the run through the onFail handle (fire-and-forget).
public void Fail() => Context.Complete("onFail");
}