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

namespace TakeoutSaaS.Application.App.Tenants.Validators;

/// <summary>
/// 租户配额使用历史查询验证器。
/// </summary>
public sealed class GetTenantQuotaUsageHistoryQueryValidator : AbstractValidator<GetTenantQuotaUsageHistoryQuery>
{
    /// <summary>
    /// 初始化验证规则。
    /// </summary>
    public GetTenantQuotaUsageHistoryQueryValidator()
    {
        RuleFor(x => x.TenantId).GreaterThan(0);
        RuleFor(x => x.Page).GreaterThanOrEqualTo(1);
        RuleFor(x => x.PageSize).InclusiveBetween(1, 100);

        // 时间范围校验
        When(x => x.StartDate.HasValue && x.EndDate.HasValue, () =>
        {
            RuleFor(x => x.EndDate!.Value).GreaterThanOrEqualTo(x => x.StartDate!.Value);
        });
    }
}

