package com.madeu.controller.web.webhome;

import java.util.HashMap;

import com.madeu.service.web.webhome.WebHomeService;
import com.madeu.service.web.webmember.WebMemberService;
import com.madeu.service.web.webmenu.WebMenuService;
import org.springframework.beans.factory.annotation.Autowired;
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 com.madeu.init.ManagerDraftAction;
import com.madeu.util.HttpUtil;
import com.madeu.util.RequestLogUtil;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;


@Slf4j
@Controller
public class WebHomeController extends ManagerDraftAction{

	@Autowired
	private WebHomeService webHomeService;
	@Autowired
	private WebMenuService webMenuService;
	/**
	 * 홈 화면으로 이동.
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/")
	public String  homeIntro(HttpSession session,HttpServletRequest request, Model model) {
		log.debug("WebHomeController  homeIntro START");
		
		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();

		try{
			if(!webCheckLogin(session)){
				return "/web/login/login";
			}
			else{
				// 접속 로그 저장
				HashMap<String, Object> visitLogParamMap = RequestLogUtil.getVisitLogParameterMap(request);
				visitLogParamMap.put("regId", "SYSTEM");
				visitLogParamMap.put("modId", "SYSTEM");
				visitLogParamMap.put("workType", "home");
//				visitLogService.insertVisitLog(visitLogParamMap);

			    paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
				HashMap<String, Object> menuData = new HashMap<>();
				menuData.put("menuName","예약현황");
				paramMap.put("menuClass",webMenuService.selectMenuCode(menuData).get("menuCode"));

				map = webHomeService.selectListHomeIntro(paramMap);
				model.addAttribute("menuClass", map.get("menuClass"));
				model.addAttribute("selectUseYn", map.get("selectUseYn"));
				model.addAttribute("insertUseYn", map.get("insertUseYn"));
				model.addAttribute("updateUseYn", map.get("updateUseYn"));
				model.addAttribute("deleteUseYn", map.get("deleteUseYn"));
				model.addAttribute("downloadUseYn", map.get("downloadUseYn"));
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		log.debug("WebHomeController  homeIntro END");
		return "/web/home/home";
	}

	/**2
	 * 홈 화면으로 이동.
	 *
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value="/webhome/homeIntro.do")
	public String  homeIntro2(HttpSession session,HttpServletRequest request, Model model) {
		log.debug("WebHomeController  homeIntro2 START");

		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();
		try{
			if(!webCheckLogin(session)){
				return "/web/login/login";
			}
			else{
				// 접속 로그 저장
				HashMap<String, Object> visitLogParamMap = RequestLogUtil.getVisitLogParameterMap(request);
				visitLogParamMap.put("regId", "SYSTEM");
				visitLogParamMap.put("modId", "SYSTEM");
				visitLogParamMap.put("workType", "home");
//				visitLogService.insertVisitLog(visitLogParamMap);
				paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
				map = webHomeService.selectListHomeIntro(paramMap);
				model.addAttribute("menuClass", map.get("menuClass"));
				model.addAttribute("selectUseYn", map.get("selectUseYn"));
				model.addAttribute("insertUseYn", map.get("insertUseYn"));
				model.addAttribute("updateUseYn", map.get("updateUseYn"));
				model.addAttribute("deleteUseYn", map.get("deleteUseYn"));
				model.addAttribute("downloadUseYn", map.get("downloadUseYn"));
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		log.debug("WebHomeController  homeIntro2 END");
		return "/web/home/home";
	}
}