class FundRepository {

	@Transactional
	public List<Fund> save(List<Fund> funds, RequestInfo requestInfo) {

		ModelMapper mapper = new ModelMapper();
		FundContract contract;
		Map<String, Object> message = new HashMap<>();

		if (persistThroughKafka != null && !persistThroughKafka.isEmpty()
				&& persistThroughKafka.equalsIgnoreCase("yes")) {

			FundRequest request = new FundRequest();
			request.setRequestInfo(requestInfo);
			request.setFunds(new ArrayList<>());

			for (Fund f : funds) {

				contract = new FundContract();
				contract.setCreatedDate(new Date());
				mapper.map(f, contract);
				request.getFunds().add(contract);

			}
			message.put("fund_create", request);
			fundQueueRepository.add(message);

			return funds;
		} else {

			List<Fund> resultList = new ArrayList<Fund>();

			for (Fund f : funds) {

				resultList.add(save(f));
			}

			FundRequest request = new FundRequest();
			request.setRequestInfo(requestInfo);
			request.setFunds(new ArrayList<>());

			for (Fund f : resultList) {

				contract = new FundContract();
				contract.setCreatedDate(new Date());
				mapper.map(f, contract);
				request.getFunds().add(contract);

			}

			message.put("fund_create", request);
			fundQueueRepository.addToSearch(message);

			return resultList;
		}

	}

	@Autowired public  FundRepository(FundJdbcRepository fundJdbcRepository, MastersQueueRepository fundQueueRepository,
			FinancialConfigurationService financialConfigurationService, FundESRepository fundESRepository,
			@Value("${persist.through.kafka}") String persistThroughKafka);

}