using Microsoft.Extensions.Options;

namespace ZB.MOM.WW.ScadaBridge.DataConnectionLayer.Tests;

/// <summary>
/// Regression: <see cref="DataConnectionOptions"/> intervals/timeouts drive the
/// DCL reconnect/tag-resolution timers and the seed-read retry loop; a
/// zero/negative duration (or a non-positive <c>SeedReadMaxAttempts</c>) must be
/// rejected at startup by an <see cref="IValidateOptions{TOptions}"/> with a
/// clear, key-naming message rather than surfacing later at runtime.
/// </summary>
public class DataConnectionOptionsValidatorTests
{
    private static ValidateOptionsResult Validate(DataConnectionOptions options) =>
        new DataConnectionOptionsValidator().Validate(Options.DefaultName, options);

    [Fact]
    public void DefaultOptions_AreValid()
    {
        var result = Validate(new DataConnectionOptions());
        Assert.True(result.Succeeded, result.FailureMessage);
    }

    [Fact]
    public void ZeroReconnectInterval_IsRejected()
    {
        var result = Validate(new DataConnectionOptions { ReconnectInterval = TimeSpan.Zero });
        Assert.True(result.Failed);
        Assert.Contains("ReconnectInterval", result.FailureMessage);
    }

    [Fact]
    public void NonPositiveSeedReadMaxAttempts_IsRejected()
    {
        var result = Validate(new DataConnectionOptions { SeedReadMaxAttempts = 0 });
        Assert.True(result.Failed);
        Assert.Contains("SeedReadMaxAttempts", result.FailureMessage);
    }
}
