class SpiToXs2aAccountDetailsMapper {

    public Xs2aCardAccountDetails mapToXs2aCardAccountDetails(SpiCardAccountDetails cardAccountDetails) {
        return Optional.ofNullable(cardAccountDetails)
                   .map(ad -> new Xs2aCardAccountDetails(
                            ad.getAspspAccountId(),
                            ad.getResourceId(),
                            ad.getMaskedPan(),
                            ad.getCurrency(),
                            ad.getName(),
                            ad.getDisplayName(),
                            ad.getProduct(),
                            mapToAccountType(ad.getCashSpiAccountType()),
                            mapToAccountStatus(ad.getSpiAccountStatus()),
                            mapToXs2aUsageType(ad.getUsageType()),
                            ad.getDetails(),
                            balanceMapper.mapToXs2aBalanceList(ad.getBalances()),
                            Optional.ofNullable(ad.getCreditLimit()).map(spiToXs2aAmountMapper::mapToXs2aAmount).orElse(null),
                            ad.getOwnerName()
                        )
                   )
                   .orElse(null);

    }

}