namespace MxGateway.Client; /// Configuration for automatic retry behavior on transient gRPC call failures. public sealed class MxGatewayClientRetryOptions { /// Gets the maximum number of attempts (initial + retries); default is 2. public int MaxAttempts { get; init; } = 2; /// Gets the initial delay between retry attempts; default is 200 milliseconds. public TimeSpan Delay { get; init; } = TimeSpan.FromMilliseconds(200); /// Gets the maximum delay between retry attempts; default is 2 seconds. public TimeSpan MaxDelay { get; init; } = TimeSpan.FromSeconds(2); /// Gets a value indicating whether to add randomness to retry delays; default is true. public bool UseJitter { get; init; } = true; /// Validates the retry options and throws if any constraint is violated. public void Validate() { if (MaxAttempts <= 0) { throw new ArgumentOutOfRangeException( nameof(MaxAttempts), "The retry max attempts value must be greater than zero."); } if (Delay <= TimeSpan.Zero) { throw new ArgumentOutOfRangeException( nameof(Delay), "The retry delay must be greater than zero."); } if (MaxDelay <= TimeSpan.Zero) { throw new ArgumentOutOfRangeException( nameof(MaxDelay), "The retry max delay must be greater than zero."); } if (MaxDelay < Delay) { throw new ArgumentOutOfRangeException( nameof(MaxDelay), "The retry max delay must be greater than or equal to the retry delay."); } } }