class AccountAccessValidator {

    public ValidationResult validate(AisConsent aisConsent, boolean withBalance) {
        if (withBalance) {
            AisConsentData aisConsentData = aisConsent.getConsentData();

            if (aisConsentData.getAllPsd2() != null) {
                return ValidationResult.valid();
            }

            if (EnumSet.of(AccountAccessType.ALL_ACCOUNTS, AccountAccessType.ALL_ACCOUNTS_WITH_OWNER_NAME)
                    .contains(aisConsentData.getAvailableAccountsWithBalance())) {

                return ValidationResult.valid();
            }

            if (CollectionUtils.isEmpty(aisConsent.getAccess().getBalances())) {
                return ValidationResult.invalid(ErrorType.AIS_401, CONSENT_INVALID);
            }
        }

        return ValidationResult.valid();
    }

}