using System.Runtime.Versioning;
using DragonISO.Engine.NdiInterop;

namespace DragonISO.Engine.Tests.Interop;

// NdiInteropPInvoke is marked [SupportedOSPlatform("windows")] because it
// P/Invokes the Windows-only NDI runtime. The pure NormalizeGroups helper
// doesn't actually touch native code, but it inherits the platform tag from
// the enclosing class. Re-declaring SupportedOSPlatform here silences CA1416
// â€” these tests still only run on Windows (the Engine.Tests project itself
// is platform-agnostic but xunit only schedules them when the OS supports).
[SupportedOSPlatform("windows")]

// NdiInteropPInvoke.NormalizeGroups is internal; the engine tests project has
// access via InternalsVisibleTo applied to DragonISO.Engine.NdiInterop.
public class NdiInteropNormalizeGroupsTests
{
    [Theory]
    [InlineData(null,             null)]
    [InlineData("",               null)]
    [InlineData("   ",            null)]
    [InlineData("Public",         "Public")]   // already canonical
    [InlineData("public",         "Public")]   // lowercase -> canonical (the bug fix)
    [InlineData("PUBLIC",         "Public")]   // shouty -> canonical
    [InlineData("PuBlIc",         "Public")]   // mixed case -> canonical
    [InlineData("Dragon-ISO-input", "Dragon-ISO-input")] // custom group: pass through
    [InlineData("Public,Dragon-ISO-input",   "Public,Dragon-ISO-input")]
    [InlineData("public,Dragon-ISO-input",   "Public,Dragon-ISO-input")] // mixed list normalizes the standard one only
    [InlineData("Dragon-ISO-input,PUBLIC",   "Dragon-ISO-input,Public")]
    [InlineData("  public  ,  Dragon-ISO-input  ", "Public,Dragon-ISO-input")] // whitespace trimmed per part
    public void NormalizeGroups_Maps(string? input, string? expected)
    {
        NdiInteropPInvoke.NormalizeGroups(input).Should().Be(expected);
    }
}
