using ZB.MOM.WW.ScadaBridge.AuditLog.Site;

namespace ZB.MOM.WW.ScadaBridge.AuditLog.Tests.Site;

/// <summary>
/// Tests for <see cref="SiteAuditRetentionOptions"/> clamping (PLAN-04 Task 2).
/// The resolved knobs guard the daily site retention job against misconfiguration:
/// retention days are clamped to [1, 90]; the purge interval is clamped away from
/// TimeSpan.Zero (an Akka/Timer spin footgun).
/// </summary>
public class SiteAuditRetentionOptionsTests
{
    [Theory]
    [InlineData(0, 1)]     // clamp floor
    [InlineData(7, 7)]     // default passthrough
    [InlineData(365, 90)]  // clamp ceiling (spec: min 1, max 90)
    public void ResolvedRetentionDays_Clamps(int configured, int expected)
        => Assert.Equal(expected, new SiteAuditRetentionOptions { RetentionDays = configured }.ResolvedRetentionDays);

    [Fact]
    public void Defaults_Are_SevenDays_DailyPurge_FiveMinuteInitialDelay()
    {
        var o = new SiteAuditRetentionOptions();
        Assert.Equal(7, o.ResolvedRetentionDays);
        Assert.Equal(TimeSpan.FromHours(24), o.ResolvedPurgeInterval);
        Assert.Equal(TimeSpan.FromMinutes(5), o.InitialDelay);
    }

    [Fact]
    public void ResolvedPurgeInterval_ClampsZeroToOneMinute()
        => Assert.Equal(TimeSpan.FromMinutes(1),
            new SiteAuditRetentionOptions { PurgeInterval = TimeSpan.Zero }.ResolvedPurgeInterval);
}
