namespace CMSMicroservice.Application.CommissionCQ.Queries.GetWeeklyCommissionPool;

public class GetWeeklyCommissionPoolQueryValidator : AbstractValidator<GetWeeklyCommissionPoolQuery>
{
    public GetWeeklyCommissionPoolQueryValidator()
    {
        RuleFor(x => x.WeekDefinitionId)
            .GreaterThan(0)
            .WithMessage("شماره هفته نمی‌تواند صفر باشد");
    }

    public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
    {
        var result = await ValidateAsync(
            ValidationContext<GetWeeklyCommissionPoolQuery>.CreateWithOptions(
                (GetWeeklyCommissionPoolQuery)model,
                x => x.IncludeProperties(propertyName)));

        if (result.IsValid)
            return Array.Empty<string>();

        return result.Errors.Select(e => e.ErrorMessage);
    };
}
