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

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.eactive.eai.rms.common.util.CamelCaseUtil;

@Controller
public class AdapterCountRetrieveController {
   
   @Autowired 
   private AdapterCountRetrieveService service;
   
   @RequestMapping(value= "/onl/adapter/retrieve/adapterCountRetrieve.view")
   public String viewList(HttpServletRequest request, @RequestParam(value = "cmd", required = false ) String cmd ) throws Exception {
      if (cmd == null || "LIST".equals(cmd.toUpperCase())) {
         cmd = "";
      } else {
         cmd = CamelCaseUtil.converCamelCase(cmd);
      }
      String path = request.getServletPath();
      return path.split("[.]")[0] + cmd;
   }
   
   @RequestMapping(value= "/onl/adapter/retrieve/adapterCountRetrieve.json", params = "cmd=LIST")
   public ResponseEntity<List<Map<String, Object>>> list(String searchAdapterGroup, String searchInstanceName) {
      
      List<Map<String, Object>> selectList = service.selectList(searchAdapterGroup, searchInstanceName);
      
      return ResponseEntity.ok().body(selectList);
   }

}