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

namespace TakeoutSaaS.Application.App.Products.Validators;

/// <summary>
/// 替换 SKU 验证器。
/// </summary>
public sealed class ReplaceProductSkusCommandValidator : AbstractValidator<ReplaceProductSkusCommand>
{
    /// <summary>
    /// 初始化验证规则。
    /// </summary>
    public ReplaceProductSkusCommandValidator()
    {
        RuleFor(x => x.ProductId).GreaterThan(0);
        RuleForEach(x => x.Skus).ChildRules(sku =>
        {
            sku.RuleFor(x => x.SkuCode).NotEmpty().MaximumLength(64);
            sku.RuleFor(x => x.Price).GreaterThan(0);
            sku.RuleFor(x => x.OriginalPrice).GreaterThan(0).When(x => x.OriginalPrice.HasValue);
            sku.RuleFor(x => x.StockQuantity).GreaterThanOrEqualTo(0).When(x => x.StockQuantity.HasValue);
            sku.RuleFor(x => x.SortOrder).GreaterThanOrEqualTo(0);
        });
    }
}
