class BudgetDetailRepository {

    @Transactional
    public List<BudgetDetail> save(final List<BudgetDetail> budgetDetails, final RequestInfo requestInfo) {

        final BudgetDetailMapper mapper = new BudgetDetailMapper();

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

            final BudgetDetailRequest request = new BudgetDetailRequest();
            request.setRequestInfo(requestInfo);
            request.setBudgetDetails(new ArrayList<>());

            for (final BudgetDetail iac : budgetDetails)
                request.getBudgetDetails().add(mapper.toContract(iac));

            budgetDetailQueueRepository.addToQue(request);

            return budgetDetails;
        } else {

            final List<BudgetDetail> resultList = new ArrayList<BudgetDetail>();

            for (final BudgetDetail iac : budgetDetails)
                resultList.add(save(iac));

            final BudgetDetailRequest request = new BudgetDetailRequest();
            request.setRequestInfo(requestInfo);
            request.setBudgetDetails(new ArrayList<>());

            for (final BudgetDetail iac : resultList)
                request.getBudgetDetails().add(mapper.toContract(iac));

            budgetDetailQueueRepository.addToSearchQue(request);

            return resultList;
        }

    }

    @Autowired public  BudgetDetailRepository(final BudgetDetailJdbcRepository budgetDetailJdbcRepository,
                                  final BudgetDetailQueueRepository budgetDetailQueueRepository,
                                  @Value("${persist.through.kafka}") final String persistThroughKafka,
                                  FinancialConfigurationContractRepository financialConfigurationContractRepository,
                                  BudgetDetailESRepository budgetDetailESRepository
    );

}