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

namespace TakeoutSaaS.Application.App.Products.Validators;

/// <summary>
/// 替换媒资验证器。
/// </summary>
public sealed class ReplaceProductMediaCommandValidator : AbstractValidator<ReplaceProductMediaCommand>
{
    /// <summary>
    /// 初始化验证规则。
    /// </summary>
    public ReplaceProductMediaCommandValidator()
    {
        RuleFor(x => x.ProductId).GreaterThan(0);
        RuleForEach(x => x.MediaAssets).ChildRules(asset =>
        {
            asset.RuleFor(x => x.Url).NotEmpty().MaximumLength(512);
            asset.RuleFor(x => x.Caption).MaximumLength(256);
            asset.RuleFor(x => x.SortOrder).GreaterThanOrEqualTo(0);
        });
    }
}
