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

namespace TakeoutSaaS.Application.App.Products.Validators;

/// <summary>
/// 创建商品命令验证器。
/// </summary>
public sealed class CreateProductCommandValidator : AbstractValidator<CreateProductCommand>
{
    /// <summary>
    /// 初始化验证规则。
    /// </summary>
    public CreateProductCommandValidator()
    {
        RuleFor(x => x.StoreId).GreaterThan(0);
        RuleFor(x => x.CategoryId).GreaterThan(0);
        RuleFor(x => x.SpuCode).NotEmpty().MaximumLength(32);
        RuleFor(x => x.Name).NotEmpty().MaximumLength(128);
        RuleFor(x => x.Subtitle).MaximumLength(256);
        RuleFor(x => x.Unit).MaximumLength(16);
        RuleFor(x => x.Price).GreaterThanOrEqualTo(0);
        RuleFor(x => x.OriginalPrice).GreaterThanOrEqualTo(0).When(x => x.OriginalPrice.HasValue);
        RuleFor(x => x.StockQuantity).GreaterThanOrEqualTo(0).When(x => x.StockQuantity.HasValue);
        RuleFor(x => x.MaxQuantityPerOrder).GreaterThan(0).When(x => x.MaxQuantityPerOrder.HasValue);
        RuleFor(x => x.SalesMonthly).GreaterThanOrEqualTo(0);
        RuleFor(x => x.TagsJson).MaximumLength(2000);
        RuleFor(x => x.RemainStock).GreaterThanOrEqualTo(0).When(x => x.RemainStock.HasValue);
        RuleFor(x => x.SoldoutReason).MaximumLength(256);
        RuleFor(x => x.CoverImage).MaximumLength(256);
        RuleFor(x => x.GalleryImages).MaximumLength(1024);
    }
}
