namespace CMSMicroservice.Application.UserCQ.Commands.CreateNewOtpToken;
public class CreateNewOtpTokenCommandValidator : AbstractValidator<CreateNewOtpTokenCommand>
{
    public CreateNewOtpTokenCommandValidator()
    {
        RuleFor(model => model.Mobile)
            .NotEmpty();
        RuleFor(model => model.Purpose)
            .NotEmpty();
    }
    public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
    {
        var result = await ValidateAsync(ValidationContext<CreateNewOtpTokenCommand>.CreateWithOptions((CreateNewOtpTokenCommand)model, x => x.IncludeProperties(propertyName)));
        if (result.IsValid)
            return Array.Empty<string>();
        return result.Errors.Select(e => e.ErrorMessage);
    };
}
