class ConsentServiceInternal implements ConsentService {

    @Override
    @Transactional(rollbackFor = WrongChecksumException.class)
    public CmsResponse<CmsCreateConsentResponse> createConsent(CmsConsent cmsConsent) throws WrongChecksumException {

        if (cmsConsent.getFrequencyPerDay() == null) {
            log.info("TPP ID: [{}]. Consent cannot be created, because request contains no allowed frequency per day",
                     cmsConsent.getTppInformation().getTppInfo().getAuthorisationNumber());
            return CmsResponse.<CmsCreateConsentResponse>builder()
                       .error(LOGICAL_ERROR)
                       .build();
        }
        ConsentEntity consentEntityFromMapper = cmsConsentMapper.mapToNewConsentEntity(cmsConsent);
        ConsentEntity consent = adjustConsentEntity(consentEntityFromMapper, cmsConsent.getConsentType());
        tppInfoRepository.findByAuthorisationNumber(cmsConsent.getTppInformation().getTppInfo().getAuthorisationNumber())
            .ifPresent(tppInfo -> consent.getTppInformation().setTppInfo(tppInfo));

        ConsentEntity savedConsent = aisConsentRepository.verifyAndSave(consent);

        if (savedConsent.getId() != null) {
            return CmsResponse.<CmsCreateConsentResponse>builder()
                       .payload(new CmsCreateConsentResponse(savedConsent.getExternalId(),
                                                             cmsConsentMapper.mapToCmsConsent(savedConsent, Collections.emptyList(), Collections.emptyMap())))
                       .build();

        } else {
            log.info("TPP ID: [{}], External Consent ID: [{}]. Consent cannot be created, because when saving to DB got null ID",
                     cmsConsent.getTppInformation().getTppInfo().getAuthorisationNumber(), savedConsent.getExternalId());
            return CmsResponse.<CmsCreateConsentResponse>builder()
                       .error(TECHNICAL_ERROR)
                       .build();
        }
    }

}