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

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

/// <summary>
/// Eager startup validation for <see cref="SiteAuditRetentionOptions"/>
/// (arch-review 08 round 2 NF4). Although the option class self-clamps at
/// resolve time, the validator still fails a boot with a plainly-wrong config
/// (zero retention window, zero/negative purge period, negative initial delay)
/// so the operator learns at startup rather than trusting a silent clamp.
/// <c>PurgeIntervalOverride</c> is test-only and left unvalidated.
/// </summary>
public class SiteAuditRetentionOptionsValidatorTests
{
    [Fact]
    public void DefaultOptions_AreValid()
    {
        var validator = new SiteAuditRetentionOptionsValidator();
        Assert.True(validator.Validate(null, new SiteAuditRetentionOptions()).Succeeded);
    }

    [Fact]
    public void ZeroRetentionDays_Fails()
    {
        var validator = new SiteAuditRetentionOptionsValidator();
        var result = validator.Validate(null, new SiteAuditRetentionOptions { RetentionDays = 0 });
        Assert.False(result.Succeeded);
        Assert.Contains(result.Failures!,
            f => f.Contains(nameof(SiteAuditRetentionOptions.RetentionDays), StringComparison.Ordinal));
    }

    [Fact]
    public void ZeroPurgeInterval_Fails()
    {
        var validator = new SiteAuditRetentionOptionsValidator();
        var result = validator.Validate(null,
            new SiteAuditRetentionOptions { PurgeInterval = TimeSpan.Zero });
        Assert.False(result.Succeeded);
        Assert.Contains(result.Failures!,
            f => f.Contains(nameof(SiteAuditRetentionOptions.PurgeInterval), StringComparison.Ordinal));
    }

    [Fact]
    public void NegativeInitialDelay_Fails()
    {
        var validator = new SiteAuditRetentionOptionsValidator();
        var result = validator.Validate(null,
            new SiteAuditRetentionOptions { InitialDelay = TimeSpan.FromSeconds(-1) });
        Assert.False(result.Succeeded);
        Assert.Contains(result.Failures!,
            f => f.Contains(nameof(SiteAuditRetentionOptions.InitialDelay), StringComparison.Ordinal));
    }
}
