using System;
namespace Svrnty.CQRS.Events.Abstractions.Configuration;
///
/// Configuration for dead letter queue behavior.
///
public class DeadLetterQueueConfiguration
{
///
/// Gets or sets whether DLQ is enabled for this stream.
///
public bool Enabled { get; set; }
///
/// Gets or sets the name of the dead letter stream.
/// If not specified, defaults to {StreamName}-dlq.
///
public string? DeadLetterStreamName { get; set; }
///
/// Gets or sets the maximum number of delivery attempts before sending to DLQ.
///
public int MaxDeliveryAttempts { get; set; } = 3;
///
/// Gets or sets the delay between retry attempts.
///
public TimeSpan? RetryDelay { get; set; }
///
/// Gets or sets whether to store the original event in the DLQ.
///
public bool? StoreOriginalEvent { get; set; }
///
/// Gets or sets whether to store error details in the DLQ.
///
public bool? StoreErrorDetails { get; set; }
///
/// Validates the DLQ configuration.
///
/// Thrown when configuration is invalid.
public void Validate()
{
if (Enabled)
{
if (MaxDeliveryAttempts <= 0)
throw new ArgumentException("MaxDeliveryAttempts must be positive", nameof(MaxDeliveryAttempts));
if (RetryDelay.HasValue && RetryDelay.Value < TimeSpan.Zero)
throw new ArgumentException("RetryDelay cannot be negative", nameof(RetryDelay));
}
}
}