class InstrumentMapper {

    public InstrumentSearchContract toSearchContract(InstrumentSearch instrumentSearch) {

        InstrumentSearchContract contract = new InstrumentSearchContract();

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

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

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

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

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

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

            contract.setInstrumentVouchers(instrumentVouchers);

        }

        contract.setPayee(instrumentSearch.getPayee());
        contract.setSerialNo(instrumentSearch.getSerialNo());
        contract.setTransactionDate(instrumentSearch.getTransactionDate());
        contract.setTransactionNumber(instrumentSearch.getTransactionNumber());
        contract.setTransactionType(instrumentSearch.getTransactionType() != null
                ? TransactionTypeContract.valueOf(instrumentSearch.getTransactionType().name()) : null);
        contract.setPayinSlipId(instrumentSearch.getPayinSlipId());
        contract.setReconciledAmount(instrumentSearch.getReconciledAmount());
        contract.setReconciledOn(instrumentSearch.getReconciledOn());
        contract.setCreatedBy(instrumentSearch.getCreatedBy());
        contract.setCreatedDate(instrumentSearch.getCreatedDate());
        contract.setLastModifiedBy(instrumentSearch.getLastModifiedBy());
        contract.setLastModifiedDate(instrumentSearch.getLastModifiedDate());
        contract.setTenantId(instrumentSearch.getTenantId());
        contract.setPageSize(instrumentSearch.getPageSize());
        contract.setOffset(instrumentSearch.getOffset());
        contract.setSortBy(instrumentSearch.getSortBy());
        contract.setIds(instrumentSearch.getIds());
        contract.setFinancialStatuses(instrumentSearch.getFinancialStatuses());
        contract.setInstrumentTypes(instrumentSearch.getInstrumentTypes());
        contract.setTransactionFromDate(instrumentSearch.getTransactionFromDate());
        contract.setTransactionToDate(instrumentSearch.getTransactionToDate());
        contract.setDeleteReason(instrumentSearch.getDeleteReason());
        return contract;
    }

}