namespace CMSMicroservice.Application.UserCQ.Commands.SetPasswordForUser;
public class SetPasswordForUserCommandValidator : AbstractValidator<SetPasswordForUserCommand>
{
    public SetPasswordForUserCommandValidator()
    {
        RuleFor(model => model.UserId)
            .NotNull();
        RuleFor(model => model.NewPassword)
            .NotEmpty();
        RuleFor(model => model.ConfirmPassword)
            .NotEmpty();
    }
    public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
    {
        var result = await ValidateAsync(ValidationContext<SetPasswordForUserCommand>.CreateWithOptions((SetPasswordForUserCommand)model, x => x.IncludeProperties(propertyName)));
        if (result.IsValid)
            return Array.Empty<string>();
        return result.Errors.Select(e => e.ErrorMessage);
    };
}
