class SpiToXs2aAccountDetailsMapper {

    public Xs2aAccountDetails mapToXs2aAccountDetails(SpiAccountDetails accountDetails) {
        return Optional.ofNullable(accountDetails)
                   .map(ad -> new Xs2aAccountDetails(
                            ad.getAspspAccountId(),
                            ad.getResourceId(),
                            ad.getIban(),
                            ad.getBban(),
                            ad.getPan(),
                            ad.getMaskedPan(),
                            ad.getMsisdn(),
                            ad.getCurrency(),
                            ad.getName(),
                            ad.getDisplayName(),
                            ad.getProduct(),
                            mapToAccountType(ad.getCashSpiAccountType()),
                            mapToAccountStatus(ad.getSpiAccountStatus()),
                            ad.getBic(),
                            ad.getLinkedAccounts(),
                            mapToXs2aUsageType(ad.getUsageType()),
                            ad.getDetails(),
                            balanceMapper.mapToXs2aBalanceList(ad.getBalances()),
                            accountDetails.getOwnerName(),
                            Optional.ofNullable(accountDetails.getOwnerAddress()).map(spiToXs2aAddressMapper::mapToAddress).orElse(null)
                        )
                   )
                   .orElse(null);
    }

}