using System; namespace Svrnty.CQRS.Events.Abstractions.Configuration; /// /// Configuration for stream lifecycle management. /// public class LifecycleConfiguration { /// /// Gets or sets whether to automatically create the stream if it doesn't exist. /// public bool AutoCreate { get; set; } = true; /// /// Gets or sets whether to automatically archive old events. /// public bool AutoArchive { get; set; } /// /// Gets or sets the age after which events should be archived. /// public TimeSpan? ArchiveAfter { get; set; } /// /// Gets or sets the location where archived events should be stored. /// public string? ArchiveLocation { get; set; } /// /// Gets or sets whether to automatically delete old events. /// public bool AutoDelete { get; set; } /// /// Gets or sets the age after which events should be deleted. /// public TimeSpan? DeleteAfter { get; set; } /// /// Validates the lifecycle configuration. /// /// Thrown when configuration is invalid. public void Validate() { if (AutoArchive) { if (!ArchiveAfter.HasValue) throw new ArgumentException("ArchiveAfter must be specified when AutoArchive is enabled", nameof(ArchiveAfter)); if (ArchiveAfter.Value <= TimeSpan.Zero) throw new ArgumentException("ArchiveAfter must be positive", nameof(ArchiveAfter)); if (string.IsNullOrWhiteSpace(ArchiveLocation)) throw new ArgumentException("ArchiveLocation must be specified when AutoArchive is enabled", nameof(ArchiveLocation)); } if (AutoDelete) { if (!DeleteAfter.HasValue) throw new ArgumentException("DeleteAfter must be specified when AutoDelete is enabled", nameof(DeleteAfter)); if (DeleteAfter.Value <= TimeSpan.Zero) throw new ArgumentException("DeleteAfter must be positive", nameof(DeleteAfter)); } if (AutoArchive && AutoDelete && ArchiveAfter.HasValue && DeleteAfter.HasValue) { if (DeleteAfter.Value <= ArchiveAfter.Value) throw new ArgumentException("DeleteAfter must be greater than ArchiveAfter", nameof(DeleteAfter)); } } }