using FluentValidation;
using TakeoutSaaS.Application.App.Finance.Transactions.Queries;

namespace TakeoutSaaS.Application.App.Finance.Transactions.Validators;

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