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

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

/// <summary>
/// Eager startup validation for <see cref="SiteAuditReconciliationOptions"/>
/// (arch-review 08 round 2 NF4). A zero tick interval spins the reconciliation
/// singleton, a zero batch pulls nothing, and a zero stalled-cycle threshold
/// would fire the stalled signal on the first non-draining cycle.
/// <see cref="SiteAuditReconciliationOptions.ReconciliationIntervalOverride"/>
/// is test-only and left unvalidated.
/// </summary>
public class SiteAuditReconciliationOptionsValidatorTests
{
    [Fact]
    public void DefaultOptions_AreValid()
    {
        var validator = new SiteAuditReconciliationOptionsValidator();
        Assert.True(validator.Validate(null, new SiteAuditReconciliationOptions()).Succeeded);
    }

    [Fact]
    public void ZeroReconciliationInterval_Fails()
    {
        var validator = new SiteAuditReconciliationOptionsValidator();
        var result = validator.Validate(null,
            new SiteAuditReconciliationOptions { ReconciliationIntervalSeconds = 0 });
        Assert.False(result.Succeeded);
        Assert.Contains(result.Failures!,
            f => f.Contains(nameof(SiteAuditReconciliationOptions.ReconciliationIntervalSeconds), StringComparison.Ordinal));
    }

    [Fact]
    public void ZeroBatchSize_Fails()
    {
        var validator = new SiteAuditReconciliationOptionsValidator();
        var result = validator.Validate(null,
            new SiteAuditReconciliationOptions { BatchSize = 0 });
        Assert.False(result.Succeeded);
        Assert.Contains(result.Failures!,
            f => f.Contains(nameof(SiteAuditReconciliationOptions.BatchSize), StringComparison.Ordinal));
    }

    [Fact]
    public void ZeroStalledCycles_Fails()
    {
        var validator = new SiteAuditReconciliationOptionsValidator();
        var result = validator.Validate(null,
            new SiteAuditReconciliationOptions { StalledAfterNonDrainingCycles = 0 });
        Assert.False(result.Succeeded);
        Assert.Contains(result.Failures!,
            f => f.Contains(nameof(SiteAuditReconciliationOptions.StalledAfterNonDrainingCycles), StringComparison.Ordinal));
    }
}
