using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Driver.AbCip.Cli.Commands;

namespace ZB.MOM.WW.OtOpcUa.Driver.AbCip.Cli.Tests;

/// <summary>
///     Covers <see cref="SubscribeCommand.ValidateInterval(int)"/> — the guard that
///     stops a zero / negative <c>--interval-ms</c> from reaching <c>SubscribeAsync</c>
///     as a non-positive <see cref="TimeSpan"/>.
/// </summary>
[Trait("Category", "Unit")]
public sealed class SubscribeCommandIntervalTests
{
    /// <summary>Verifies that validate interval rejects non-positive milliseconds.</summary>
    /// <param name="badMs">A non-positive interval value that should be rejected.</param>
    [Theory]
    [InlineData(0)]
    [InlineData(-1)]
    [InlineData(-500)]
    public void ValidateInterval_rejects_non_positive(int badMs)
    {
        var ex = Should.Throw<CliFx.Exceptions.CommandException>(
            () => SubscribeCommand.ValidateInterval(badMs));
        ex.Message.ShouldContain("--interval-ms");
    }

    /// <summary>Verifies that validate interval accepts positive milliseconds.</summary>
    /// <param name="goodMs">A positive interval value that should be accepted.</param>
    [Theory]
    [InlineData(1)]
    [InlineData(250)]
    [InlineData(60_000)]
    public void ValidateInterval_accepts_positive(int goodMs)
    {
        Should.NotThrow(() => SubscribeCommand.ValidateInterval(goodMs));
    }
}
