using System; using Svrnty.CQRS.Events.Abstractions.Storage; namespace Svrnty.CQRS.Events.Abstractions.Configuration; /// /// Configuration for event stream retention policy. /// Supports time-based and/or size-based retention. /// public record RetentionPolicyConfig : IRetentionPolicy { /// /// Stream name this policy applies to. /// Use "*" for default policy. /// public required string StreamName { get; init; } /// /// Maximum age for events (null = no time-based retention). /// Example: TimeSpan.FromDays(30) keeps events for 30 days. /// public TimeSpan? MaxAge { get; init; } /// /// Maximum number of events to retain (null = no size-based retention). /// Example: 1000000 keeps only the last 1 million events. /// public long? MaxEventCount { get; init; } /// /// Whether this policy is enabled. /// Default: true /// public bool Enabled { get; init; } = true; /// /// Validates the retention policy configuration. /// /// Thrown when configuration is invalid. public void Validate() { if (string.IsNullOrWhiteSpace(StreamName)) throw new ArgumentException("StreamName cannot be null or whitespace", nameof(StreamName)); if (MaxAge.HasValue && MaxAge.Value <= TimeSpan.Zero) throw new ArgumentException("MaxAge must be positive", nameof(MaxAge)); if (MaxEventCount.HasValue && MaxEventCount.Value <= 0) throw new ArgumentException("MaxEventCount must be positive", nameof(MaxEventCount)); if (!MaxAge.HasValue && !MaxEventCount.HasValue) throw new ArgumentException("At least one of MaxAge or MaxEventCount must be specified"); } }