using FluentValidation;
using TakeoutSaaS.Application.App.Products.Commands;

namespace TakeoutSaaS.Application.App.Products.Validators;

/// <summary>
/// 替换规格验证器。
/// </summary>
public sealed class ReplaceProductAttributesCommandValidator : AbstractValidator<ReplaceProductAttributesCommand>
{
    /// <summary>
    /// 初始化验证规则。
    /// </summary>
    public ReplaceProductAttributesCommandValidator()
    {
        RuleFor(x => x.ProductId).GreaterThan(0);
        RuleForEach(x => x.AttributeGroups).ChildRules(group =>
        {
            group.RuleFor(x => x.Name).NotEmpty().MaximumLength(64);
            group.RuleFor(x => x.SortOrder).GreaterThanOrEqualTo(0);
            group.RuleForEach(x => x.Options).ChildRules(opt =>
            {
                opt.RuleFor(x => x.Name).NotEmpty().MaximumLength(64);
                opt.RuleFor(x => x.SortOrder).GreaterThanOrEqualTo(0);
            });
        });
    }
}
