class ConsentMapper {

    public CmsConsent mapToCmsConsent(AisConsent consent) {
        CmsConsent cmsConsent = new CmsConsent();
        AccountAccessInfo access = consent.getAccess();

        AisConsentData aisConsentData = new AisConsentData(toCmsAccessType(consent.getAvailableAccounts()), toCmsAccessType(consent.getAllPsd2()), toCmsAccessType(consent.getAvailableAccountsWithBalance()), false);
        byte[] aisConsentDataBytes = consentDataMapper.getBytesFromConsentData(aisConsentData);
        cmsConsent.setConsentData(aisConsentDataBytes);

        ConsentTppInformation tppInformation = new ConsentTppInformation();
        tppInformation.setTppInfo(toTppInfo(consent.getTppInfo()));
        tppInformation.setTppFrequencyPerDay(consent.getRequestedFrequencyPerDay());
        tppInformation.setTppRedirectPreferred(consent.isTppRedirectPreferred());
        cmsConsent.setTppInformation(tppInformation);

        AuthorisationTemplate authorisationTemplate = new AuthorisationTemplate();
        authorisationTemplate.setTppRedirectUri(toTppRedirectUti(consent.getTppInfo().getCancelTppRedirectUri()));
        cmsConsent.setAuthorisationTemplate(authorisationTemplate);

        cmsConsent.setFrequencyPerDay(consent.getAllowedFrequencyPerDay());
        cmsConsent.setInternalRequestId(UUID.randomUUID().toString());
        cmsConsent.setValidUntil(consent.getValidUntil());
        cmsConsent.setRecurringIndicator(consent.isRecurringIndicator());
        cmsConsent.setPsuIdDataList(Collections.singletonList(toPsuIdData(consent.getPsuInfo())));
        cmsConsent.setConsentType(ConsentType.AIS);
        cmsConsent.setTppAccountAccesses(toAccountAccess(access));
        cmsConsent.setAspspAccountAccesses(AccountAccess.EMPTY_ACCESS);
        cmsConsent.setConsentStatus(ConsentStatus.RECEIVED);
        return cmsConsent;
    }

}