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

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

public sealed class PublishAnnouncementCommandValidatorTests
{
    private readonly PublishAnnouncementCommandValidator _validator = new();

    [Fact]
    public void GivenAnnouncementIdZero_WhenValidate_ThenShouldHaveError()
    {
        // Arrange
        var command = AnnouncementTestData.CreateValidPublishCommand() with { AnnouncementId = 0 };

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

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

    [Fact]
    public void GivenNullRowVersion_WhenValidate_ThenShouldHaveError()
    {
        // Arrange
        var command = AnnouncementTestData.CreateValidPublishCommand() 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.CreateValidPublishCommand() 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.CreateValidPublishCommand();

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

        // Assert
        result.ShouldNotHaveAnyValidationErrors();
    }
}
