package utis.wall.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.View;
import utis.wall.common.util.CommonUtil;
import utis.wall.service.MainService;

/**
 * @Class Name  : MainController.java
 * @Description : 메인 Controller 
 * @Modification Information  
 * 
 *  수정일			수정자		수정내용
 *  -------------	---------	-------------------------------
 *  2015. 9. 9.	YJLEE	    최초생성
 * 
 * @author YJLEE
 * @since 2015. 9. 9.
 * @version 1.0
 * @see
 * 
 */

@Controller
@RequestMapping("/main")
@ResponseStatus(value = HttpStatus.ACCEPTED)
public class MainController {
	
	/** Json Parser View */
	@Resource(name="jsonTemplate")
	private View jsonView;
	
	@Resource(name="MainService")
	private MainService service;
	
	/**
	 * 상황판 메인 호출
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/index")
	public ModelAndView main() throws Exception {
		return new ModelAndView("main/main");
	}
	
	/**
	 * 돌발 A등급 &전면통제조회 
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getFooter")
	public ModelAndView getFooter(HttpServletRequest  req, HttpServletResponse res) throws Exception {
		return new ModelAndView(jsonView, "data", service.getFooter(req));
	}
	
	/**
	 * 도시 SELECTBOX조회
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getSelectCity")
	public ModelAndView getSelectCity(HttpServletRequest  req, HttpServletResponse res) throws Exception {
		return new ModelAndView(jsonView, "data", service.getSelectCity(req));
	}
	
	/**
	 * ROAD SELECTBOX조회
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getSelectRoad")
	public ModelAndView getSelectRoad(HttpServletRequest  req, HttpServletResponse res) throws Exception {
		return new ModelAndView(jsonView, "data", service.getSelectRoad(req));
	}
	
	/**
	 * 시내도로 CCTV 조회
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getCCTV")
	public ModelAndView getCCtv(HttpServletRequest  req, HttpServletResponse res) throws Exception {
		return new ModelAndView(jsonView, "data", service.getCCTV(req));
	}
	
	/**
	 * 돌발정보조회
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getIMS")
	public ModelAndView getIMS(HttpServletRequest  req, HttpServletResponse res) throws Exception {
		return new ModelAndView(jsonView, "data", service.getIMS(req));
	}
	
	/**
	 * CCTV동영상화면 조회
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/cctvPlayer")
	public ModelAndView getCctvPlayer(HttpServletRequest  req, HttpServletResponse res) throws Exception {
		return new CommonUtil().setPageParam(req, "main/cctvPlayer");
	}
	
	/**
	 * 고속도로/국도 CCTV조회
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getCctvRoad")
	public ModelAndView getCctvRoad(HttpServletRequest  req, HttpServletResponse res) throws Exception {
		return new ModelAndView(jsonView, "data", service.getCctvRoad(req));
	}
	
	/**
	 * 고속도로/국토 CCTV동영상화면 조회
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/roadCctvPlayer")
	public ModelAndView getRoadCctvPlayer(HttpServletRequest  req, HttpServletResponse res) throws Exception {
		return new CommonUtil().setPageParam(req, "main/roadCctvPlayer");
	}
	
	
	/**
	 * OBEID 조회
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getObeId")
	public ModelAndView getObeId(HttpServletRequest  req, HttpServletResponse res) throws Exception {
		return new ModelAndView(jsonView, "data", service.getObeId(req));
	}
	
	
	/**
	 * iFrameE05(도로공사 교통센터) 화면 호출
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/iFrameE05")
	public ModelAndView iFrameE05(HttpServletRequest  req, HttpServletResponse res) throws Exception {
		return new CommonUtil().setPageParam(req, "main/iFrameE05");
	}
	
	/**
	 * 고속도로/국도 CCTV(도로공사 교통센터) 조회
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getCctvRoadE05")
	public ModelAndView getCctvRoadE05(HttpServletRequest  req, HttpServletResponse res) throws Exception {
		return new ModelAndView(jsonView, "data", service.getCctvRoadE05(req));
	}
	
	/**
	 * 맥어드레이스 인증 확인
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getMacAddressAuth")
	public ModelAndView getMacAddressAuth(HttpServletRequest  req) throws Exception {
		
		return new ModelAndView(jsonView, "data", service.getMacAddressAuth(req));
	}
	
	@RequestMapping("/getSignalInfo")
	public ModelAndView getSignalInfo(HttpServletRequest  req, HttpServletResponse res) throws Exception {
		
		return new ModelAndView(jsonView, "data", service.getSignalInfo(req));
	}

	@RequestMapping({"getSigInfoPhaseDetail.do"})
	public ModelAndView getSigInfoPhaseDetail(HttpServletRequest req, HttpServletResponse res) throws Exception {
		return new ModelAndView(this.jsonView, "data", this.service.getSigInfoPhaseDetail(req));
	}

	@RequestMapping({"/getGeoLocation.do"})
	public ModelAndView geoLocation(HttpServletRequest req, HttpServletResponse res) throws Exception {
		return new ModelAndView("main/geoLocation");
	}

	@RequestMapping({"/getWeatherInfo.do"})
	public ModelAndView getWeatherInfo(HttpServletRequest req, HttpServletResponse res) throws Exception {
		return new ModelAndView(this.jsonView, "data", this.service.getWeatherInfo(req));
	}

	@RequestMapping({"/getSpaceWeatherInfo.do"})
	public ModelAndView getSpaceWeatherInfo(HttpServletRequest req, HttpServletResponse res) throws Exception {
		return new ModelAndView(this.jsonView, "data", this.service.getSpaceWeatherInfo(req));
	}
	
	@RequestMapping({"/getConnectionAuth.do"})
	public ModelAndView getConnectionAuth(HttpServletRequest req, HttpServletResponse res) throws Exception {
		if(service.getConnectionAuth(req)) {
			return new ModelAndView(this.jsonView, "data", true);
		}
		
		return new ModelAndView(this.jsonView, "data", false);
	}
	
	@RequestMapping({"/getTrafficUpdateTime.do"})
	public ModelAndView getTrafficUpdateTime(HttpServletRequest req, HttpServletResponse res) throws Exception {
		return new ModelAndView(this.jsonView, "data", this.service.getTrafficUpdateTime(req));
	}
}
