using FluentValidation; using Microsoft.Extensions.Options; namespace PnvPanel.Application.Plans; public sealed class ChangePlanCommandValidator : AbstractValidator { public ChangePlanCommandValidator(IOptions plansOptions) { RuleFor(x => x) .Must(x => x.PlanId.HasValue ^ x.CustomConfigCount.HasValue) .WithMessage("Укажите либо PlanId, либо CustomConfigCount — ровно одно из двух."); When( x => x.CustomConfigCount.HasValue, () => RuleFor(x => x.CustomConfigCount!.Value) .InclusiveBetween(plansOptions.Value.MinCustomConfigCount, plansOptions.Value.MaxCustomConfigCount) ); RuleFor(x => x.ConfigIdsToRevoke).Must(ids => ids.Distinct().Count() == ids.Count); } }