class InstrumentMapper {

    public InstrumentContract toContract(Instrument instrument) {

        InstrumentContract contract = new InstrumentContract();

        contract.setId(instrument.getId());
        contract.setAmount(instrument.getAmount());
        contract.setBank(instrument.getBank());
        contract.setBankAccount(instrument.getBankAccount());
        contract.setBranchName(instrument.getBranchName());
        contract.setDrawer(instrument.getDrawer());
        contract.setFinancialStatus(instrument.getFinancialStatus());
        contract.setRemittanceVoucherId(instrument.getRemittanceVoucherId());

        if (instrument.getInstrumentType() != null)
            contract.setInstrumentType(typeMapper.toContract(instrument.getInstrumentType()));

        if (instrument.getSurrenderReason() != null)
            contract.setSurrenderReason(srMapper.toContract(instrument.getSurrenderReason()));

        if (instrument.getInstrumentVouchers() != null) {

            List<InstrumentVoucherContract> instrumentVouchers = new ArrayList<>();

            if (instrument.getInstrumentVouchers() != null)
                for (InstrumentVoucher iv : instrument.getInstrumentVouchers())
                    instrumentVouchers
                            .add(InstrumentVoucherContract.builder().instrument(contract.getId())
                                    .voucherHeaderId(iv.getVoucherHeaderId()).receiptHeaderId(iv.getReceiptHeaderId()).build());

            contract.setInstrumentVouchers(instrumentVouchers);

        }

        contract.setPayee(instrument.getPayee());
        contract.setSerialNo(instrument.getSerialNo());
        contract.setTransactionDate(instrument.getTransactionDate());
        contract.setTransactionNumber(instrument.getTransactionNumber());
        contract.setTransactionType(instrument.getTransactionType() != null
                ? TransactionTypeContract.valueOf(instrument.getTransactionType().name()) : null);
        contract.setPayinSlipId(instrument.getPayinSlipId());
        contract.setReconciledAmount(instrument.getReconciledAmount());
        contract.setReconciledOn(instrument.getReconciledOn());
        contract.setCreatedBy(instrument.getCreatedBy());
        contract.setCreatedDate(instrument.getCreatedDate());
        contract.setLastModifiedBy(instrument.getLastModifiedBy());
        contract.setLastModifiedDate(instrument.getLastModifiedDate());
        contract.setTenantId(instrument.getTenantId());
        contract.setDeleteReason(instrument.getDeleteReason());
        return contract;
    }

}