class InstrumentMapper {

    public Instrument toDomain(InstrumentContract contract) {

        Instrument instrument = new Instrument();

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

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

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

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

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

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

            instrument.setInstrumentVouchers(instrumentVouchers);

        }

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

}