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

namespace TakeoutSaaS.Application.App.Products.Validators;

/// <summary>
/// 商品沽清命令验证器。
/// </summary>
public sealed class SoldoutProductCommandValidator : AbstractValidator<SoldoutProductCommand>
{
    /// <summary>
    /// 初始化验证规则。
    /// </summary>
    public SoldoutProductCommandValidator()
    {
        RuleFor(x => x.ProductId).GreaterThan(0);
        RuleFor(x => x.RemainStock).GreaterThanOrEqualTo(0);
        RuleFor(x => x.Reason).MaximumLength(256);
        RuleFor(x => x.RecoverAt)
            .NotNull()
            .When(x => x.Mode == ProductSoldoutMode.Timed);
    }
}
