package com.eactive.eai.rms.onl.manage.serviceinfo.addfailover;

import com.eactive.eai.rms.common.base.OnlBaseAnnotationController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.List;

/**
 * <pre>
 *     1. 기능 : 에러코드 관리 화면의 컨트롤러
 * </pre>
 *
 * @author :
 * @version : $Revision: 1.24 $
 * @since : rms 1.0
 */

@Controller
public class AddFailoverController extends OnlBaseAnnotationController {

	@Autowired
	@Qualifier("addFailoverManService")
	private AddFailoverManService service;

	@GetMapping(value = "/onl/admin/service/addFailoverMan.view")
	public String view() {
		return "/onl/admin/service/addFailoverMan";
	}

	@GetMapping(value = "/onl/admin/service/addFailoverMan.view", params = "cmd=DETAIL")
	public String viewDetail() {
		return "/onl/admin/service/addFailoverManDetail";
	}

//   @RequestMapping(value= "/onl/admin/service/addFailoverMan.view")
//   private 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;
//   }

	@PostMapping(value = "/onl/admin/service/addFailoverMan.json", params = "cmd=LIST")
	private ResponseEntity<List<AddFailoverUI>> selectList(AddFailoverSearchUI addFailoverSearchUI) throws Exception {

		List<AddFailoverUI> resultList = service.selectList(addFailoverSearchUI);

		return ResponseEntity.ok(resultList);

	}

	@PostMapping(value = "/onl/admin/service/addFailoverMan.json", params = "cmd=UPDATE_PRPTY")
	private ResponseEntity<String> insert(AddFailoverUI addFailoverUI) throws Exception {

		service.update(addFailoverUI);

		return ResponseEntity.ok("update success");
	}

}