package egovframework.controller;

import egovframework.service.impl.CommonServiceImpl;
import egovframework.service.impl.MainServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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.net.ConnectException;
import java.sql.SQLException;
import java.util.Map;

@Slf4j
@RequiredArgsConstructor
@Controller
public class MainController {

    private final MainServiceImpl mainService;
    private final CommonServiceImpl commonService;

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

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

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

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

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

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

    @RequestMapping(value = "/relate/siteMap.do", method = RequestMethod.GET)
    public String siteMap(Model model) {
        model.addAttribute("siteSubInfo", "subWrap");
        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) throws SQLException, ConnectException{
        model.addAttribute("siteSubInfo", "subWrap");
        model.addAttribute("popupObject", this.mainService.getPopupObject(paramMap));
        return "main/popup";
    }

}