class CmsCorePaymentMapper {

    public PaymentInitiationJson mapToPaymentInitiationJson(PisPayment pisPayment) {
        return Optional.ofNullable(pisPayment)
                   .map(ref -> {
                       PaymentInitiationJson payment = new PaymentInitiationJson();
                       payment.setCreditorAddress(cmsAddressMapper.mapToAddress(pisPayment.getCreditorAddress()));
                       payment.setRemittanceInformationStructured(mapToRemittanceInformationStructured(pisPayment.getRemittanceInformationStructured()));
                       payment.setCreditorAgent(pisPayment.getCreditorAgent());
                       payment.setCreditorName(pisPayment.getCreditorName());
                       payment.setCreditorAccount(mapToAccountReference(pisPayment.getCreditorAccount()));
                       payment.setDebtorAccount(mapToAccountReference(pisPayment.getDebtorAccount()));
                       payment.setEndToEndIdentification(pisPayment.getEndToEndIdentification());
                       payment.setInstructionIdentification(pisPayment.getInstructionIdentification());
                       Amount amount = new Amount();
                       amount.setAmount(pisPayment.getAmount().toPlainString());
                       amount.setCurrency(mapToCurrency(pisPayment.getCurrency()));
                       payment.setInstructedAmount(amount);
                       payment.setPurposeCode(PurposeCode.fromValue(pisPayment.getPurposeCode()));
                       payment.setRemittanceInformationUnstructured(pisPayment.getRemittanceInformationUnstructured());
                       payment.setRequestedExecutionDate(pisPayment.getRequestedExecutionDate());
                       payment.setUltimateCreditor(pisPayment.getUltimateCreditor());
                       payment.setUltimateDebtor(pisPayment.getUltimateDebtor());

                       return payment;
                   }).orElse(null);
    }

}