namespace Domain.Tests.ValueObjects;

using Domain.ValueObjects;
using FluentAssertions;
using Xunit;

public class EmailTests
{
    [Theory]
    [InlineData("test@example.com")]
    [InlineData("user.name@domain.org")]
    [InlineData("UPPER@CASE.COM")]
    public void Create_WithValidEmail_ShouldSucceed(string email)
    {
        var result = Email.Create(email);

        result.Value.Should().Be(email.ToLowerInvariant());
    }

    [Theory]
    [InlineData("")]
    [InlineData("   ")]
    [InlineData(null)]
    public void Create_WithEmptyEmail_ShouldThrow(string? email)
    {
        var act = () => Email.Create(email!);

        act.Should().Throw<ArgumentException>()
            .WithMessage("*Email is required*");
    }

    [Theory]
    [InlineData("notanemail")]
    [InlineData("missing@domain")]
    [InlineData("@nodomain.com")]
    [InlineData("spaces in@email.com")]
    public void Create_WithInvalidFormat_ShouldThrow(string email)
    {
        var act = () => Email.Create(email);

        act.Should().Throw<ArgumentException>()
            .WithMessage("*Invalid email format*");
    }

    [Fact]
    public void Equals_WithSameValue_ShouldBeEqual()
    {
        var email1 = Email.Create("test@example.com");
        var email2 = Email.Create("TEST@EXAMPLE.COM");

        email1.Should().Be(email2);
    }

    [Fact]
    public void ImplicitConversion_ToString_ShouldWork()
    {
        var email = Email.Create("test@example.com");

        string value = email;

        value.Should().Be("test@example.com");
    }
}
