using FluentValidation.TestHelper;
using SIGCM2.Application.Auth.Login;

namespace SIGCM2.Application.Tests.Auth.Login;

public class LoginCommandValidatorTests
{
    private readonly LoginCommandValidator _validator = new();

    // Happy path: valid command passes validation
    [Fact]
    public void Validate_ValidCommand_ShouldHaveNoErrors()
    {
        var command = new LoginCommand("admin", "@Diego550@");
        var result = _validator.TestValidate(command);
        result.ShouldNotHaveAnyValidationErrors();
    }

    // Scenario: empty username → validation error referencing Username
    [Fact]
    public void Validate_EmptyUsername_ShouldHaveErrorForUsername()
    {
        var command = new LoginCommand("", "@Diego550@");
        var result = _validator.TestValidate(command);
        result.ShouldHaveValidationErrorFor(c => c.Username);
    }

    // Triangulation: whitespace-only username
    [Fact]
    public void Validate_WhitespaceUsername_ShouldHaveErrorForUsername()
    {
        var command = new LoginCommand("   ", "@Diego550@");
        var result = _validator.TestValidate(command);
        result.ShouldHaveValidationErrorFor(c => c.Username);
    }

    // Scenario: missing password → validation error referencing Password
    [Fact]
    public void Validate_EmptyPassword_ShouldHaveErrorForPassword()
    {
        var command = new LoginCommand("admin", "");
        var result = _validator.TestValidate(command);
        result.ShouldHaveValidationErrorFor(c => c.Password);
    }

    // Triangulation: null-equivalent (empty string is how records serialize missing fields)
    [Fact]
    public void Validate_BothEmpty_ShouldHaveErrorsForBothFields()
    {
        var command = new LoginCommand("", "");
        var result = _validator.TestValidate(command);
        result.ShouldHaveValidationErrorFor(c => c.Username);
        result.ShouldHaveValidationErrorFor(c => c.Password);
    }
}
