namespace CMSMicroservice.Application.NetworkMembershipCQ.Queries.GetMyNetworkTree;

public class GetMyNetworkTreeQueryValidator : AbstractValidator<GetMyNetworkTreeQuery>
{
    public GetMyNetworkTreeQueryValidator()
    {
        RuleFor(x => x.MaxDepth)
            .InclusiveBetween(1, 100)
            .WithMessage("عمق درخت باید بین 1 تا 100 باشد");
    }

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

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

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