package egovframework.com.its.web.server.controller;

import egovframework.com.its.web.server.service.CommonService;
import egovframework.com.its.web.server.vo.CctvCtlrVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@RequiredArgsConstructor
@Controller
@Slf4j
public class TrafficController {

    private final CommonService commonService;

    @RequestMapping(value = "/traffic/cctv.do", method = RequestMethod.GET)
    public String cctv(Model model, @Value("${apiKey}") String apiKey) {
        model.addAttribute("subTitle", "CCTV");
        model.addAttribute("key", apiKey);
        return "traffic/cctv.tiles";
    }

    @RequestMapping(value = "/traffic/popupCctv.do", method = RequestMethod.GET)
    public String popupCctv(Model model, @RequestParam Map<String, Object> paramMap) {
        String cctv_nmbr = paramMap.get("cctv_mngm_nmbr").toString();
        CctvCtlrVO vo = this.commonService.getOneCctvCtlr(cctv_nmbr);
        model.addAttribute("cctv", vo);
        model.addAttribute("subTitle", vo.getIstl_lctn_nm() + " CCTV 영상");
        return "traffic/cctvPopup.empty";
    }

    @RequestMapping(value = "/traffic/popupCctvM.do", method = RequestMethod.GET)
    public String popupCctvM(Model model, @RequestParam Map<String, Object> paramMap, HttpServletResponse response) {
        String cctv_nmbr = paramMap.get("cctv_mngm_nmbr").toString();
        CctvCtlrVO vo = this.commonService.getOneCctvCtlr(cctv_nmbr);
        model.addAttribute("cctv", vo);
        model.addAttribute("subTitle", vo.getIstl_lctn_nm() + " CCTV 영상");
        return "traffic/cctvPopupM.empty";
    }

    @RequestMapping(value = "/traffic/vms.do", method = RequestMethod.GET)
    public String vms(Model model, @Value("${apiKey}") String apiKey) {
        model.addAttribute("subTitle", "VMS");
        model.addAttribute("key", apiKey);
        return "traffic/vms.tiles";
    }

    @RequestMapping(value = "/traffic/incd.do", method = RequestMethod.GET)
    public String incd(Model model, @Value("${apiKey}") String apiKey) {
        model.addAttribute("subTitle", "돌발 정보");
        model.addAttribute("key", apiKey);
        return "traffic/incd.tiles";
    }

    @RequestMapping(value = "/traffic/realtime.do", method = RequestMethod.GET)
    public String realtime(Model model, @Value("${apiKey}") String apiKey) {
        model.addAttribute("atrdNmList", this.commonService.getAtrdNm());
        model.addAttribute("subTitle", "소통정보");
        model.addAttribute("key", apiKey);
        return "traffic/realtime.tiles";
    }

}