class KeyVaultConfigValidator implements ConstraintValidator<ValidKeyVaultConfig, DefaultKeyVaultConfig> {

    @Override
    public boolean isValid(
            DefaultKeyVaultConfig keyVaultConfig, ConstraintValidatorContext constraintValidatorContext) {
        if (keyVaultConfig == null || keyVaultConfig.getKeyVaultType() == null) {
            return true;
        }

        KeyVaultType keyVaultType = keyVaultConfig.getKeyVaultType();

        List<Boolean> outcomes = new ArrayList<>();
        if (keyVaultType == KeyVaultType.AZURE) {

            if (!keyVaultConfig.getProperties().containsKey("url")) {
                constraintValidatorContext.disableDefaultConstraintViolation();
                constraintValidatorContext
                        .buildConstraintViolationWithTemplate("URL is required")
                        .addConstraintViolation();
                outcomes.add(Boolean.FALSE);
            }
        }

        if (keyVaultType == KeyVaultType.HASHICORP) {

            if (!keyVaultConfig.getProperties().containsKey("url")) {
                constraintValidatorContext.disableDefaultConstraintViolation();
                constraintValidatorContext
                        .buildConstraintViolationWithTemplate("URL is required")
                        .addConstraintViolation();
                outcomes.add(Boolean.FALSE);
            }

            PathValidator pathValidator = new PathValidator();
            ValidPath validPath = this.getClass().getAnnotation(ValidPath.class);
            pathValidator.initialize(validPath);

            if (keyVaultConfig.getProperties().containsKey("tlsKeyStorePath")) {
                Path tlsKeyStorePath = Paths.get(keyVaultConfig.getProperties().get("tlsKeyStorePath"));
                outcomes.add(pathValidator.isValid(tlsKeyStorePath, constraintValidatorContext));
            }
            if (keyVaultConfig.getProperties().containsKey("tlsTrustStorePath")) {
                Path tlsKeyStorePath = Paths.get(keyVaultConfig.getProperties().get("tlsTrustStorePath"));
                outcomes.add(pathValidator.isValid(tlsKeyStorePath, constraintValidatorContext));
            }
        }

        if (keyVaultType == KeyVaultType.AWS) {

            if (keyVaultConfig.getProperties().containsKey("endpoint")) {
                if (!keyVaultConfig.getProperties().get("endpoint").matches("^https?://.+$")) {
                    constraintValidatorContext.disableDefaultConstraintViolation();
                    constraintValidatorContext
                        .buildConstraintViolationWithTemplate("must be a valid AWS service endpoint URL with scheme")
                        .addConstraintViolation();
                    outcomes.add(Boolean.FALSE);
                }
            }
        }

        return outcomes.stream().allMatch(Boolean::booleanValue);
    }

}