using FluentValidation;
using TakeoutSaaS.Application.App.Finance.Overview.Queries;
using TakeoutSaaS.Domain.Finance.Enums;

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

/// <summary>
/// 财务概览查询验证器。
/// </summary>
public sealed class GetFinanceOverviewDashboardQueryValidator : AbstractValidator<GetFinanceOverviewDashboardQuery>
{
    /// <summary>
    /// 初始化验证规则。
    /// </summary>
    public GetFinanceOverviewDashboardQueryValidator()
    {
        RuleFor(x => x.Dimension)
            .Must(value => value is FinanceCostDimension.Tenant or FinanceCostDimension.Store)
            .WithMessage("dimension 非法");

        RuleFor(x => x)
            .Must(query =>
                query.Dimension != FinanceCostDimension.Store ||
                (query.StoreId.HasValue && query.StoreId.Value > 0))
            .WithMessage("storeId 非法");

        RuleFor(x => x.CurrentUtc)
            .Must(value => value.Year is >= 2000 and <= 2100)
            .WithMessage("currentUtc 非法");
    }
}
