package com.eactive.eai.rms.onl.adapter.count;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.eactive.eai.rms.onl.common.service.jspcall.JspCallAgentUtilService;

@Service
public class AdapterCountRetrieveService {
   
   
   @Autowired 
   @Qualifier("OnlJspCallAgentUtilService")
   private JspCallAgentUtilService jspCallAgentUtilService;
   
   public List<Map<String, Object>> selectList(String searchAdapterGroup, String searchInstanceName) {
      
      Map<String,String> filter = new HashMap<String,String>();
      
      List<Map<String, Object>> response = null;
      
      if (StringUtils.isNotBlank(searchInstanceName)) {
         response = jspCallAgentUtilService.agentCallByGetMethod("adapter_count_agent.jsp", new ArrayList<String>() {{ add(searchInstanceName); }}, new HashMap<>(), filter);
      } else {
         response = jspCallAgentUtilService.agentCallByGetMethod("adapter_count_agent.jsp", new HashMap<>(), filter);
      }
       
      if (StringUtils.isNotBlank(searchAdapterGroup)) {
         response = response.stream().filter(row -> String.valueOf(row.get("AdptrBzwkGroupName")).contains(searchAdapterGroup)).collect(Collectors.toList());
      }
      
      return response;
   }

}