using Predictalytics.Application.Services;
using Xunit;

namespace Predictalytics.Application.Tests.Services;

public class StorageGovernorTests
{
    [Theory]
    [InlineData(10.0, 90.0, 90, 30, 90)]   // far below budget -> full window
    [InlineData(72.0, 90.0, 90, 30, 90)]   // exactly at 80% -> still full
    [InlineData(90.0, 90.0, 90, 30, 30)]   // at budget -> min window
    [InlineData(100.0, 90.0, 90, 30, 30)]  // over budget -> min window
    [InlineData(72.9, 90.0, 90, 30, 87)]   // 81% of budget -> slightly tightened
    [InlineData(81.0, 90.0, 90, 30, 60)]   // 90% of budget -> halfway tightened
    public void ComputeEffectiveRetentionDays_Interpolates(
        double sizeGb, double maxGb, int configured, int min, int expected)
    {
        Assert.Equal(expected, StorageGovernor.ComputeEffectiveRetentionDays(sizeGb, maxGb, configured, min));
    }

    [Fact]
    public void HalfwayIntoZone_IsBetweenMinAndConfigured()
    {
        // 85 GB of 90 (softStart 72) -> t ~0.72 -> days between 30 and 90
        var days = StorageGovernor.ComputeEffectiveRetentionDays(85.0, 90.0, 90, 30);
        Assert.InRange(days, 31, 89);
    }
}
