class ConsentService {

    public ResponseObject<Xs2aScaStatusResponse> getConsentAuthorisationScaStatus(String consentId, String authorisationId) {
        ResponseObject<ConsentScaStatus> consentScaStatusResponse = consentAuthorisationService.getConsentAuthorisationScaStatus(consentId, authorisationId);
        if (consentScaStatusResponse.hasError()) {
            return ResponseObject.<Xs2aScaStatusResponse>builder()
                       .fail(consentScaStatusResponse.getError())
                       .build();
        }

        ConsentScaStatus consentScaStatus = consentScaStatusResponse.getBody();
        ScaStatus scaStatus = consentScaStatus.getScaStatus();

        if (scaStatus.isNotFinalisedStatus()) {
            Xs2aScaStatusResponse response = new Xs2aScaStatusResponse(scaStatus, null);
            return ResponseObject.<Xs2aScaStatusResponse>builder()
                       .body(response)
                       .build();
        }

        ResponseObject<Boolean> beneficiaryFlagResponse = getTrustedBeneficiaryFlag(consentScaStatus.getPsuIdData(),
                                                                                    consentId, authorisationId,
                                                                                    consentScaStatus.getAccountConsent());
        if (beneficiaryFlagResponse.hasError()) {
            return ResponseObject.<Xs2aScaStatusResponse>builder()
                       .fail(beneficiaryFlagResponse.getError())
                       .build();
        }

        Boolean beneficiaryFlag = beneficiaryFlagResponse.getBody();
        Xs2aScaStatusResponse response = new Xs2aScaStatusResponse(scaStatus, beneficiaryFlag);

        return ResponseObject.<Xs2aScaStatusResponse>builder()
                   .body(response)
                   .build();
    }

}