class TrustedBeneficiariesService {

    public ResponseObject<Xs2aTrustedBeneficiariesList> getTrustedBeneficiaries(String consentId,
                                                                                String accountId,
                                                                                String requestUri) {
        xs2aEventService.recordConsentTppRequest(consentId, EventType.READ_TRUSTED_BENEFICIARIES_LIST_REQUEST_RECEIVED);

        Optional<AisConsent> aisConsentOptional = aisConsentService.getAccountConsentById(consentId);

        if (aisConsentOptional.isEmpty()) {
            return getResponseWithNotFoundConsent(consentId, accountId);
        }

        AisConsent aisConsent = aisConsentOptional.get();
        ValidationResult validationResult = getValidationResult(accountId, requestUri, aisConsent);

        if (validationResult.isNotValid()) {
            return getResponseWithValidationError(consentId, accountId, requestUri, validationResult);
        }

        SpiResponse<List<SpiTrustedBeneficiaries>> spiResponse = getSpiResponse(aisConsent, consentId, accountId);

        if (spiResponse.hasError()) {
            return getResponseWithSpiError(consentId, spiResponse);
        }

        return getSuccessfulResponse(consentId, accountId, requestUri, aisConsent, spiResponse);
    }

}