//
// Copyright (c) Stella Operations. Licensed under BUSL-1.1.
//
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace StellaOps.Registry.TokenService.Admin;
///
/// Abstraction for persistent plan rule storage.
///
public interface IPlanRuleStore
{
///
/// Gets all plan rules ordered by name.
///
Task> GetAllAsync(CancellationToken cancellationToken = default);
///
/// Gets a plan rule by ID.
///
Task GetByIdAsync(string id, CancellationToken cancellationToken = default);
///
/// Gets a plan rule by name.
///
Task GetByNameAsync(string name, CancellationToken cancellationToken = default);
///
/// Creates a new plan rule.
///
Task CreateAsync(CreatePlanRequest request, string actor, CancellationToken cancellationToken = default);
///
/// Updates an existing plan rule.
///
Task UpdateAsync(string id, UpdatePlanRequest request, string actor, CancellationToken cancellationToken = default);
///
/// Deletes a plan rule.
///
Task DeleteAsync(string id, string actor, CancellationToken cancellationToken = default);
///
/// Gets audit history for a plan.
///
Task> GetAuditHistoryAsync(
string? planId = null,
int page = 1,
int pageSize = 50,
CancellationToken cancellationToken = default);
}
///
/// Exception thrown when a plan rule version conflict occurs.
///
public sealed class PlanVersionConflictException : System.Exception
{
public PlanVersionConflictException(string planId, int expectedVersion, int actualVersion)
: base($"Plan '{planId}' version conflict: expected {expectedVersion}, actual {actualVersion}")
{
PlanId = planId;
ExpectedVersion = expectedVersion;
ActualVersion = actualVersion;
}
public string PlanId { get; }
public int ExpectedVersion { get; }
public int ActualVersion { get; }
}
///
/// Exception thrown when a plan rule is not found.
///
public sealed class PlanNotFoundException : System.Exception
{
public PlanNotFoundException(string planId)
: base($"Plan '{planId}' not found")
{
PlanId = planId;
}
public string PlanId { get; }
}
///
/// Exception thrown when a plan name already exists.
///
public sealed class PlanNameConflictException : System.Exception
{
public PlanNameConflictException(string name)
: base($"Plan with name '{name}' already exists")
{
Name = name;
}
public string Name { get; }
}