using ZB.MOM.WW.ScadaBridge.Commons.Types;

namespace ZB.MOM.WW.ScadaBridge.Commons.Tests.Types;

/// <summary>
/// Covers the shared purge-timer initial-delay rule (arch-review 04, S9): the
/// three central purge singletons must NOT wait a full (up to 24 h) interval
/// before their first tick, or a node recycled daily would never purge. The
/// initial delay is min(interval, 5 min).
/// </summary>
public class PurgeTimerScheduleTests
{
    [Fact]
    public void InitialDelay_LongInterval_IsCappedAtShortFirstTick()
    {
        // A daily (24 h) cadence must still fire its first purge within 5 minutes.
        Assert.Equal(PurgeTimerSchedule.ShortFirstTick, PurgeTimerSchedule.InitialDelay(TimeSpan.FromHours(24)));
    }

    [Fact]
    public void InitialDelay_IntervalShorterThanShortFirstTick_IsUnchanged()
    {
        // A millisecond test cadence must be preserved verbatim (min picks the interval),
        // so the existing fast-tick actor suites keep their sub-second timing.
        var fast = TimeSpan.FromMilliseconds(100);
        Assert.Equal(fast, PurgeTimerSchedule.InitialDelay(fast));
    }

    [Fact]
    public void InitialDelay_IntervalEqualToShortFirstTick_IsThatValue()
    {
        Assert.Equal(PurgeTimerSchedule.ShortFirstTick, PurgeTimerSchedule.InitialDelay(PurgeTimerSchedule.ShortFirstTick));
    }

    [Fact]
    public void ShortFirstTick_IsFiveMinutes()
    {
        Assert.Equal(TimeSpan.FromMinutes(5), PurgeTimerSchedule.ShortFirstTick);
    }
}
