using FluentValidation.TestHelper;
using TakeoutSaaS.Application.App.Tenants.Validators;
using TakeoutSaaS.Application.Tests.TestUtilities;

namespace TakeoutSaaS.Application.Tests.App.Tenants.Validators;

public sealed class UpdateAnnouncementCommandValidatorTests
{
    private readonly UpdateAnnouncementCommandValidator _validator = new();

    [Fact]
    public void GivenEmptyTitle_WhenValidate_ThenShouldHaveError()
    {
        // Arrange
        var command = AnnouncementTestData.CreateValidUpdateCommand() with { Title = "" };

        // Act
        var result = _validator.TestValidate(command);

        // Assert
        result.ShouldHaveValidationErrorFor(x => x.Title);
    }

    [Fact]
    public void GivenTitleTooLong_WhenValidate_ThenShouldHaveError()
    {
        // Arrange
        var command = AnnouncementTestData.CreateValidUpdateCommand() with { Title = new string('A', 129) };

        // Act
        var result = _validator.TestValidate(command);

        // Assert
        result.ShouldHaveValidationErrorFor(x => x.Title);
    }

    [Fact]
    public void GivenEmptyContent_WhenValidate_ThenShouldHaveError()
    {
        // Arrange
        var command = AnnouncementTestData.CreateValidUpdateCommand() with { Content = "" };

        // Act
        var result = _validator.TestValidate(command);

        // Assert
        result.ShouldHaveValidationErrorFor(x => x.Content);
    }

    [Fact]
    public void GivenNullRowVersion_WhenValidate_ThenShouldHaveError()
    {
        // Arrange
        var command = AnnouncementTestData.CreateValidUpdateCommand() with { RowVersion = null! };

        // Act
        var result = _validator.TestValidate(command);

        // Assert
        result.ShouldHaveValidationErrorFor(x => x.RowVersion);
    }

    [Fact]
    public void GivenEmptyRowVersion_WhenValidate_ThenShouldHaveError()
    {
        // Arrange
        var command = AnnouncementTestData.CreateValidUpdateCommand() with { RowVersion = Array.Empty<byte>() };

        // Act
        var result = _validator.TestValidate(command);

        // Assert
        result.ShouldHaveValidationErrorFor(x => x.RowVersion);
    }

    [Fact]
    public void GivenValidCommand_WhenValidate_ThenShouldNotHaveErrors()
    {
        // Arrange
        var command = AnnouncementTestData.CreateValidUpdateCommand();

        // Act
        var result = _validator.TestValidate(command);

        // Assert
        result.ShouldNotHaveAnyValidationErrors();
    }
}
