using FluentValidation;
using TakeoutSaaS.Application.App.Tenants.Commands;
using TakeoutSaaS.Domain.Tenants.Enums;
namespace TakeoutSaaS.Application.App.Tenants.Validators;
///
/// 创建公告命令验证器。
///
public sealed class CreateAnnouncementCommandValidator : AbstractValidator
{
///
/// 初始化验证规则。
///
public CreateAnnouncementCommandValidator()
{
RuleFor(x => x.Title)
.NotEmpty()
.MaximumLength(128);
RuleFor(x => x.Content)
.NotEmpty();
RuleFor(x => x.TargetType)
.NotEmpty();
RuleFor(x => x)
.Must(x => x.TenantId != 0 || x.PublisherScope == PublisherScope.Platform)
.WithMessage("TenantId=0 仅允许平台公告");
RuleFor(x => x.EffectiveTo)
.Must((command, effectiveTo) => !effectiveTo.HasValue || command.EffectiveFrom < effectiveTo.Value)
.WithMessage("生效开始时间必须早于结束时间");
}
}