using System;
using System.Collections.Generic;
namespace Svrnty.CQRS.Events.Abstractions.Projections;
///
/// Registry for managing projection definitions and their configurations.
///
///
///
/// Phase 7 Feature - Projection Registry:
/// The registry maintains metadata about all registered projections,
/// including which streams they consume and how they should be executed.
///
///
public interface IProjectionRegistry
{
///
/// Registers a projection with the registry.
///
/// The projection definition.
void Register(ProjectionDefinition definition);
///
/// Gets a projection definition by name.
///
/// The unique name of the projection.
/// The projection definition, or null if not found.
ProjectionDefinition? GetProjection(string projectionName);
///
/// Gets all registered projection definitions.
///
/// All projection definitions.
IEnumerable GetAllProjections();
///
/// Gets all projections that consume from a specific stream.
///
/// The name of the stream.
/// All projection definitions consuming from this stream.
IEnumerable GetProjectionsForStream(string streamName);
}
///
/// Defines a projection's configuration and behavior.
///
public sealed record ProjectionDefinition
{
///
/// The unique name of the projection.
///
public required string ProjectionName { get; init; }
///
/// The name of the stream to consume from.
///
public required string StreamName { get; init; }
///
/// The type of the projection implementation.
///
public required Type ProjectionType { get; init; }
///
/// The type of events this projection handles.
///
///
/// Null if projection implements IDynamicProjection and handles multiple event types.
///
public Type? EventType { get; init; }
///
/// Execution options for the projection.
///
public ProjectionOptions Options { get; init; } = new();
///
/// Optional description of what this projection does.
///
public string? Description { get; init; }
}
///
/// Configuration options for projection execution.
///
public sealed record ProjectionOptions
{
///
/// Number of events to read from stream per batch.
///
///
/// Default: 100. Larger batches = higher throughput but more memory.
///
public int BatchSize { get; set; } = 100;
///
/// Whether to start the projection automatically on application startup.
///
///
/// Default: true. Set to false for projections that should be started manually.
///
public bool AutoStart { get; set; } = true;
///
/// Maximum number of retry attempts for failed events.
///
///
/// Default: 3. After max retries, the projection moves to Failed state.
///
public int MaxRetries { get; set; } = 3;
///
/// Base delay for exponential backoff retry strategy.
///
///
/// Default: 1 second. Actual delay = BaseRetryDelay * 2^(attemptNumber).
///
public TimeSpan BaseRetryDelay { get; set; } = TimeSpan.FromSeconds(1);
///
/// How often to poll for new events when caught up.
///
///
/// Default: 1 second. Shorter = more responsive, longer = less database load.
///
public TimeSpan PollingInterval { get; set; } = TimeSpan.FromSeconds(1);
///
/// Whether to checkpoint after each event or only after each batch.
///
///
/// Default: false (checkpoint per batch). Set to true for exactly-once semantics
/// at the cost of higher checkpoint overhead.
///
public bool CheckpointPerEvent { get; set; } = false;
///
/// Whether this projection can be reset and rebuilt.
///
///
/// Default: true. Set to false to prevent accidental rebuilds of critical projections.
///
public bool AllowRebuild { get; set; } = true;
}