using Baya.Domain.Entities.Reviews;
using FluentValidation;

namespace Baya.Application.Features.Reviews.Commands.ModerateReview;

public sealed class ModerateReviewCommandValidator : AbstractValidator<ModerateReviewCommand>
{
    public ModerateReviewCommandValidator()
    {
        RuleFor(x => x.ReviewId).GreaterThan(0);
        RuleFor(x => x.Action)
            .NotEmpty()
            .Must(ReviewModerationAction.All.Contains)
            .WithMessage($"Action must be one of: {string.Join(", ", ReviewModerationAction.All)}.");

        // Hide and reject must carry a reason for the audit trail and the author notice.
        RuleFor(x => x.Reason)
            .NotEmpty()
            .MaximumLength(500)
            .When(x => x.Action is not null && ReviewModerationAction.RequiresReason(x.Action));
    }
}
