namespace ZB.MOM.WW.ScadaBridge.NotificationService.Tests;

/// <summary>
/// Tests for parsing the configured email transport discriminator into the two-state enum.
/// </summary>
public class EmailTransportParserTests
{
    [Theory]
    [InlineData("Smtp", EmailTransport.Smtp)]
    [InlineData("smtp", EmailTransport.Smtp)]
    [InlineData("SMTP", EmailTransport.Smtp)]
    [InlineData("Ews", EmailTransport.Ews)]
    [InlineData("ews", EmailTransport.Ews)]
    [InlineData("EWS", EmailTransport.Ews)]
    [InlineData("  ews  ", EmailTransport.Ews)]
    public void Parse_KnownTransports_ReturnsExpected(string input, EmailTransport expected)
    {
        Assert.Equal(expected, EmailTransportParser.Parse(input));
    }

    [Theory]
    [InlineData(null)]
    [InlineData("")]
    [InlineData("   ")]
    public void Parse_NullOrEmpty_DefaultsToSmtp(string? input)
    {
        // Every pre-EWS SmtpConfiguration row stores no transport; those rows are SMTP rows.
        Assert.Equal(EmailTransport.Smtp, EmailTransportParser.Parse(input));
    }

    [Theory]
    [InlineData("Graph")]
    [InlineData("smtps")]
    public void Parse_UnknownTransport_Throws(string input)
    {
        // An unknown transport must be rejected, not silently treated as SMTP.
        var ex = Assert.Throws<ArgumentException>(() => EmailTransportParser.Parse(input));
        Assert.Contains(input, ex.Message);
    }
}
