using System.Reflection;
using CliFx.Attributes;
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Driver.AbCip.Cli.Commands;

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

/// <summary>
///     Verifies that the CLI's help text is consistent with its runtime behaviour — in
///     particular that rejected types do not appear as valid options in the option description,
///     and that counts stated in CLI metadata are accurate.
/// </summary>
[Trait("Category", "Unit")]
public sealed class HelpTextConsistencyTests
{
    /// <summary>
    ///     Driver.AbCip.Cli-010 — ReadCommand's <c>--type</c> option description must NOT
    ///     list <c>Structure</c>, because <c>RejectStructure</c> will refuse it at runtime.
    ///     Listing a rejected value in the help text misleads operators.
    /// </summary>
    [Fact]
    public void ReadCommand_type_option_description_does_not_list_Structure()
    {
        var prop = typeof(ReadCommand).GetProperty(
            nameof(ReadCommand.DataType),
            BindingFlags.Public | BindingFlags.Instance)
            ?? throw new InvalidOperationException("DataType property not found on ReadCommand");

        var attr = prop.GetCustomAttribute<CommandOptionAttribute>()
            ?? throw new InvalidOperationException("CommandOptionAttribute not found on ReadCommand.DataType");

        // RejectStructure is called in ReadCommand.ExecuteAsync; listing Structure in the
        // help text as a valid --type value misleads operators (Driver.AbCip.Cli-010).
        (attr.Description ?? string.Empty).ShouldNotContain("Structure");
    }
}
