class ConsentServiceInternal implements ConsentService {

    @Override
    @Transactional
    public CmsResponse<CmsConsent> getConsentById(String consentId) {
        Optional<ConsentEntity> consentEntityOptional = consentJpaRepository.findByExternalId(consentId)
                                                            .map(aisConsentConfirmationExpirationService::checkAndUpdateOnConfirmationExpiration)
                                                            .map(this::checkAndUpdateOnExpiration);

        if (consentEntityOptional.isEmpty()) {
            log.info("Consent ID [{}]. Get consent by ID failed, couldn't find consent by its ID", consentId);
            return CmsResponse.<CmsConsent>builder()
                       .error(LOGICAL_ERROR)
                       .build();
        }

        ConsentEntity consentEntity = consentEntityOptional.get();
        consentEntity = aisConsentLazyMigrationService.migrateIfNeeded(consentEntity);

        List<AuthorisationEntity> authorisations = authorisationRepository.findAllByParentExternalIdAndType(consentEntity.getExternalId(), AuthorisationType.CONSENT);
        CmsConsent cmsConsent = cmsConsentMapper.mapToCmsConsent(consentEntity, authorisations, aisConsentUsageService.getUsageCounterMap(consentEntity));

        return CmsResponse.<CmsConsent>builder()
                   .payload(cmsConsent)
                   .build();
    }

}