using FluentValidation;
using TakeoutSaaS.Application.App.Orders.Queries;

namespace TakeoutSaaS.Application.App.Orders.Validators;

/// <summary>
/// 全部订单列表查询验证器。
/// </summary>
public sealed class SearchOrderAllListQueryValidator : AbstractValidator<SearchOrderAllListQuery>
{
    /// <summary>
    /// 初始化验证规则。
    /// </summary>
    public SearchOrderAllListQueryValidator()
    {
        RuleFor(x => x.Page).GreaterThan(0);
        RuleFor(x => x.PageSize).InclusiveBetween(1, 200);
        RuleFor(x => x.Keyword).MaximumLength(64);
        RuleFor(x => x.SortBy).MaximumLength(64);
        RuleFor(x => x)
            .Must(x => !x.StartAt.HasValue || !x.EndAt.HasValue || x.StartAt < x.EndAt)
            .WithMessage("开始时间必须早于结束时间");
    }
}
