using ZB.MOM.WW.ScadaBridge.Commons.Entities.Notifications;

namespace ZB.MOM.WW.ScadaBridge.Commons.Tests.Entities;

/// <summary>
/// Commons-NNN: locks the <see cref="NotificationRecipient"/> construction invariants
/// (exactly one contact field populated per channel; non-blank name on every path).
/// </summary>
public class NotificationRecipientTests
{
    [Fact]
    public void ForEmail_SetsEmail_LeavesPhoneNull()
    {
        var r = NotificationRecipient.ForEmail("Jane", "jane@example.com");

        Assert.Equal("Jane", r.Name);
        Assert.Equal("jane@example.com", r.EmailAddress);
        Assert.Null(r.PhoneNumber);
    }

    [Fact]
    public void ForSms_SetsPhone_LeavesEmailNull()
    {
        var r = NotificationRecipient.ForSms("Jane", "+15551234567");

        Assert.Equal("Jane", r.Name);
        Assert.Equal("+15551234567", r.PhoneNumber);
        Assert.Null(r.EmailAddress);
    }

    [Theory]
    [InlineData(null)]
    [InlineData("")]
    [InlineData("   ")]
    public void ForEmail_BlankName_Throws(string? name)
        => Assert.Throws<ArgumentException>(() => NotificationRecipient.ForEmail(name!, "jane@example.com"));

    [Theory]
    [InlineData(null)]
    [InlineData("")]
    [InlineData("   ")]
    public void ForSms_BlankName_Throws(string? name)
        => Assert.Throws<ArgumentException>(() => NotificationRecipient.ForSms(name!, "+15551234567"));

    [Fact]
    public void ForEmail_NullEmail_Throws()
        => Assert.Throws<ArgumentNullException>(() => NotificationRecipient.ForEmail("Jane", null!));

    [Fact]
    public void ForSms_NullPhone_Throws()
        => Assert.Throws<ArgumentNullException>(() => NotificationRecipient.ForSms("Jane", null!));

    [Theory]
    [InlineData(null)]
    [InlineData("")]
    [InlineData("   ")]
    public void PublicCtor_BlankName_Throws(string? name)
        => Assert.Throws<ArgumentException>(() => new NotificationRecipient(name!, "jane@example.com"));

    [Fact]
    public void PublicCtor_NullEmail_Throws()
        => Assert.Throws<ArgumentNullException>(() => new NotificationRecipient("Jane", null!));
}
