using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
using ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Cli.Commands;

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

/// <summary>
///     Driver.TwinCAT.Cli-003: the subscribe banner mechanism label is derived from the
///     <see cref="ISubscriptionHandle.DiagnosticId"/> the driver actually returned, not from
///     the <c>--poll-only</c> flag. That way the banner cannot disagree with what the driver
///     did even if a future fallback path lands the subscription somewhere unexpected.
/// </summary>
[Trait("Category", "Unit")]
public sealed class SubscribeCommandMechanismTests
{
    private sealed record StubHandle(string DiagnosticId) : ISubscriptionHandle;

    /// <summary>Verifies that DescribeMechanism returns ADS notification for native handle.</summary>
    /// <param name="diagId">The diagnostic ID of the subscription handle to classify.</param>
    [Theory]
    [InlineData("twincat-native-sub-1")]
    [InlineData("twincat-native-sub-42")]
    [InlineData("twincat-native-sub-9223372036854775807")]
    public void DescribeMechanism_returns_ADS_notification_for_native_handle(string diagId)
    {
        SubscribeCommand.DescribeMechanism(new StubHandle(diagId)).ShouldBe("ADS notification");
    }

    /// <summary>Verifies that DescribeMechanism returns polling for anything else.</summary>
    /// <param name="diagId">The diagnostic ID of the subscription handle to classify.</param>
    [Theory]
    [InlineData("pollgroup-1")]
    [InlineData("modbus-poll-7")]
    [InlineData("")]
    [InlineData("TWINCAT-NATIVE-SUB-1")] // ordinal comparison — uppercase prefix does NOT match.
    public void DescribeMechanism_returns_polling_for_anything_else(string diagId)
    {
        SubscribeCommand.DescribeMechanism(new StubHandle(diagId)).ShouldBe("polling");
    }
}
