class SpiToXs2aTrustedBeneficiariesMapper {

    public Xs2aTrustedBeneficiaries mapToXs2aTrustedBeneficiaries(SpiTrustedBeneficiaries spiTrustedBeneficiaries) {
        return Optional.ofNullable(spiTrustedBeneficiaries)
            .map(tb -> new Xs2aTrustedBeneficiaries(
                tb.getTrustedBeneficiaryId(),
                accountReferenceMapper.mapToXs2aAccountReference(tb.getDebtorAccount()),
                accountReferenceMapper.mapToXs2aAccountReference(tb.getCreditorAccount()),
                tb.getCreditorAgent(),
                tb.getCreditorName(),
                tb.getCreditorAlias(),
                tb.getCreditorId(),
                addressMapper.mapToAddress(tb.getCreditorAddress())
            ))
            .orElse(null);
    }

}