using FluentValidation;
using TakeoutSaaS.Application.App.Tenants.Commands;
using TakeoutSaaS.Application.App.Tenants.Targeting;

namespace TakeoutSaaS.Application.App.Tenants.Validators;

/// <summary>
/// 更新公告命令验证器。
/// </summary>
public sealed class UpdateAnnouncementCommandValidator : AbstractValidator<UpdateTenantAnnouncementCommand>
{
    /// <summary>
    /// 初始化验证规则。
    /// </summary>
    public UpdateAnnouncementCommandValidator()
    {
        RuleFor(x => x.Title)
            .NotEmpty()
            .MaximumLength(128);

        RuleFor(x => x.Content)
            .NotEmpty();

        RuleFor(x => x.TargetType)
            .NotEmpty()
            .Must(TenantAnnouncementTargetTypePolicy.IsAllowed)
            .WithMessage("租户端不支持该目标受众类型");

        RuleFor(x => x.RowVersion)
            .NotNull()
            .Must(rowVersion => rowVersion != null && rowVersion.Length > 0)
            .WithMessage("RowVersion 不能为空");
    }
}
