class InstrumentMapper {

    public InstrumentSearch toSearchDomain(InstrumentSearchContract contract) {

        InstrumentSearch instrumentSearch = new InstrumentSearch();

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

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

        if (contract.getSurrenderReason() != null)
            instrumentSearch.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());

            instrumentSearch.setInstrumentVouchers(instrumentVouchers);

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

}