using TeamsISO.Engine.Discovery;
using TeamsISO.Engine.Domain;

namespace TeamsISO.Engine.Tests.Domain;

public class NdiSourceParserTests
{
    [Theory]
    // ----- Legacy "Teams" brand (older Teams desktop) -----
    [InlineData("WORKSTATION-01 (Teams - Jane Doe)", "WORKSTATION-01", NdiSourceKind.Participant, "Jane Doe")]
    [InlineData("PROD-PC (Teams - Élise O'Connor)", "PROD-PC", NdiSourceKind.Participant, "Élise O'Connor")]
    [InlineData("HOST (Teams - Smith, Bob (PM))", "HOST", NdiSourceKind.Participant, "Smith, Bob (PM)")]
    // ----- Current "MS Teams" brand (the new Teams desktop client) -----
    [InlineData("WOOGLIN (MS Teams - Brendon Power)", "WOOGLIN", NdiSourceKind.Participant, "Brendon Power")]
    [InlineData("WOOGLIN (MS Teams - (Local))", "WOOGLIN", NdiSourceKind.Participant, "(Local)")]
    [InlineData("LAB-PC (MS Teams - Smith, Bob (PM))", "LAB-PC", NdiSourceKind.Participant, "Smith, Bob (PM)")]
    // ----- Defensive future-proof "Microsoft Teams" brand -----
    [InlineData("WORKSTATION (Microsoft Teams - Alex Rivera)", "WORKSTATION", NdiSourceKind.Participant, "Alex Rivera")]
    public void Parse_Participant_ExtractsMachineAndDisplayName(
        string fullName, string expectedMachine, NdiSourceKind expectedKind, string expectedDisplay)
    {
        var result = NdiSourceParser.Parse(fullName);

        result.Should().NotBeNull();
        result!.MachineName.Should().Be(expectedMachine);
        result.Kind.Should().Be(expectedKind);
        result.DisplayName.Should().Be(expectedDisplay);
        result.FullName.Should().Be(fullName);
    }

    [Theory]
    // ----- Legacy "Teams" forms -----
    [InlineData("HOST (Teams)", NdiSourceKind.ActiveSpeaker)]
    [InlineData("HOST (Teams Audio)", NdiSourceKind.Audio)]
    [InlineData("HOST (Teams Screen Share)", NdiSourceKind.ScreenShare)]
    // ----- Current "MS Teams" forms (dash-prefixed reserved suffix) -----
    [InlineData("WOOGLIN (MS Teams - Active Speaker)", NdiSourceKind.ActiveSpeaker)]
    [InlineData("WOOGLIN (MS Teams - Audio Mix)", NdiSourceKind.Audio)]
    [InlineData("WOOGLIN (MS Teams - Screen Share)", NdiSourceKind.ScreenShare)]
    public void Parse_NonParticipantKinds_ClassifyCorrectly(string fullName, NdiSourceKind expectedKind)
    {
        var result = NdiSourceParser.Parse(fullName);

        result.Should().NotBeNull();
        result!.Kind.Should().Be(expectedKind);
        result.DisplayName.Should().BeNull();
    }

    [Theory]
    [InlineData("Plain NDI Source")]
    [InlineData("HOST (Some Other Software)")]
    [InlineData("(Teams - No Machine)")]
    public void Parse_NonTeamsSource_ReturnsNull(string fullName)
    {
        var result = NdiSourceParser.Parse(fullName);
        result.Should().BeNull();
    }
}
