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

import egovframework.com.its.web.server.service.CommonService;
import egovframework.com.its.web.server.service.MainService;
import egovframework.com.its.web.server.vo.PopupVO;
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.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Map;

@Slf4j
@RequiredArgsConstructor
@Controller
public class MainController {

    private final MainService mainService;
    private final CommonService commonService;

    @RequestMapping(value = {"/","/main/Main.do"}, method = RequestMethod.GET)
    public String Main(ModelMap model) {
        return "redirect:/main/main.do";
    }

    @RequestMapping(value = {"/main/main.do"}, method = RequestMethod.GET)
    public String main(ModelMap model, @Value("${apiKey}") String apiKey) {
        model.addAttribute("siteSubInfo", "main");
        model.addAttribute("subTitle", "HOME");
        model.addAttribute("possiblePopupList", this.mainService.getPossiblePopupList());
        model.addAttribute("atrdNmList", this.commonService.getAtrdNm());
        model.addAttribute("key", apiKey);
        return "main/main.tiles";
    }

    @RequestMapping(value = "/intro/location.do", method = RequestMethod.GET)
    public String location(Model model) {
        model.addAttribute("siteSubInfo", "sub info");
        model.addAttribute("subTitle", "찾아오시는길");
        return "intro/location.tiles";
    }

    @RequestMapping(value = "/intro/service.do", method = RequestMethod.GET)
    public String service(Model model) {
        model.addAttribute("siteSubInfo", "sub info");
        model.addAttribute("subTitle", "서비스 소개");
        return "intro/service.tiles";
    }

    @RequestMapping(value = "/intro/center.do", method = RequestMethod.GET)
    public String center(Model model) {
        model.addAttribute("siteSubInfo", "sub info");
        model.addAttribute("subTitle", "센터 소개");
        return "intro/center.tiles";
    }

    @RequestMapping(value = "/relate/relateSite.do", method = RequestMethod.GET)
    public String relateSite(Model model) {
        model.addAttribute("siteSubInfo", "sub site");
        model.addAttribute("subTitle", "관련사이트");
        return "relate/relateSite.tiles";
    }

    @RequestMapping(value = "/relate/siteMap.do", method = RequestMethod.GET)
    public String siteMap(Model model) {
        model.addAttribute("siteSubInfo", "sub sitemap");
        model.addAttribute("subTitle", "사이트 맵");
        return "relate/siteMap.tiles";
    }

    @RequestMapping(value = "/main/popup.do", method = RequestMethod.GET)
    public String popup(Model model, @RequestParam Map<String, Object> paramMap) {
        model.addAttribute("siteSubInfo", "sub sitemap");
        PopupVO vo =  this.mainService.getPopupObject(paramMap);
        model.addAttribute("subTitle", vo.getTitle());
        model.addAttribute("popupObject", vo);
        return "main/popup.empty";
    }

    @RequestMapping(value = "/main/video-policy.do", method = RequestMethod.GET)
    public String videoPolicyPopup(Model model, @RequestParam Map<String, Object> paramMap) {
        model.addAttribute("siteSubInfo", "sub sitemap");
        model.addAttribute("subTitle", "영상정보처리기기 운영*관리 방침");
        return "main/video_op_policy.tiles";
    }
}