using DragonISO.Engine.Pipeline;

namespace DragonISO.Engine.Tests.Pipeline;

public class ExponentialBackoffTests
{
    [Theory]
    [InlineData(1, 1)]
    [InlineData(2, 2)]
    [InlineData(3, 4)]
    [InlineData(4, 8)]
    [InlineData(5, 16)]
    [InlineData(6, 30)] // capped at 30s
    [InlineData(7, 30)]
    public void NextDelay_FollowsExponentialSequenceWithCap(int attempt, int expectedSeconds)
    {
        var policy = new ExponentialBackoff(maxAttempts: 5, initial: TimeSpan.FromSeconds(1), cap: TimeSpan.FromSeconds(30));
        policy.NextDelay(attempt).Should().Be(TimeSpan.FromSeconds(expectedSeconds));
    }

    [Theory]
    [InlineData(1, false)]
    [InlineData(4, false)]
    [InlineData(5, false)]   // 5 attempts allowed
    [InlineData(6, true)]    // give up after the 5th
    public void ShouldGiveUp_AfterMaxAttempts(int attemptCount, bool expectGiveUp)
    {
        var policy = new ExponentialBackoff(maxAttempts: 5, initial: TimeSpan.FromSeconds(1), cap: TimeSpan.FromSeconds(30));
        policy.ShouldGiveUp(attemptCount).Should().Be(expectGiveUp);
    }
}
