package com.madeu.controller.mobile.mobilefooter;

import com.madeu.init.ManagerDraftAction;
import com.madeu.service.mobile.mobilereservation.MobileReservationService;
import com.madeu.util.HttpUtil;
import com.madeu.util.ValidationCheckUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;

@Slf4j
@Controller
public class footerController extends ManagerDraftAction {

	@Autowired
	private MobileReservationService mobileReservationService;

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

        HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
        HashMap<String, Object> map = new HashMap<String, Object>();
        try{
             if (!mobileCheckLogin(session)) {
                return "/mobile/login/login";
            } else {
                paramMap.put("loginUserId", String.valueOf(session.getAttribute("loginUserId")));
				model.addAttribute("currentPage", "home");
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            return "/mobile/login/login";
        }
        log.debug("footerController  homeIntro2 END");
        return "/mobile/home/home";
    }

    /**
     * 시술정보 페이지 화면 이동
     * 페이지 처리 없음
     * request:
     * response : msgCode, msgDesc
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/medical")
    public String medicalIntro(HttpSession session, HttpServletRequest request, Model model) {
        log.debug("footerController  medicalIntro START");

        HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
        HashMap<String, Object> map = new HashMap<String, Object>();

        try {
            if (!mobileCheckLogin(session)) {
                return "/mobile/login/login";
            } else {
                paramMap.put("loginUserId", String.valueOf(session.getAttribute("loginUserId")));
				model.addAttribute("currentPage", "medical");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return "/mobile/login/login";
        }
        log.debug("footerController  insertBoardIntro END");
        return "/mobile/medical/selectMedicalList";
    }

    /**
     * 예약 페이지 화면 이동
     * 페이지 처리 없음
     * request:
     * response : msgCode, msgDesc
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/reservation")
    public String reservationIntro(HttpSession session, HttpServletRequest request, Model model) {
        log.debug("footerController  reservationIntro START");

        HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
        HashMap<String, Object> map = new HashMap<String, Object>();

        try {
            if (!mobileCheckLogin(session)) {
                return "/mobile/login/login";
            } else {
                paramMap.put("loginUserId", String.valueOf(session.getAttribute("loginUserId")));
                paramMap.put("muUserId", String.valueOf(session.getAttribute("loginUserId")));
                paramMap.put("regId", String.valueOf(session.getAttribute("loginUserId")));
                paramMap.put("modId", String.valueOf(session.getAttribute("loginUserId")));

				// 파라미터가 있을 경우 업데이트
				if(true == ValidationCheckUtil.emptyCheck(String.valueOf(paramMap.get("userCheckYn")))){
					map = mobileReservationService.updateReserveUserCheckYn(paramMap);
				}

				model.addAttribute("currentPage","reservation");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return "/mobile/login/login";
        }
        log.debug("footerController  reservationIntro END");
        return "/mobile/reservation/selectReservationList";
    }

    /**
     * 마이페이지 화면 이동
     * 페이지 처리 없음
     * request:
     * response : msgCode, msgDesc
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/mypage")
    public String loginIntro(HttpSession session, HttpServletRequest request, Model model) {
        log.debug("footerController  myPageIntro START");

        HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
        HashMap<String, Object> map = new HashMap<String, Object>();

        try {
            if (!mobileCheckLogin(session)) {
                return "/mobile/login/login";
            } else {
                paramMap.put("loginUserId", String.valueOf(session.getAttribute("loginUserId")));
				model.addAttribute("currentPage", "mypage");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return "/mobile/login/login";
        }
        log.debug("footerController  insertBoardIntro END");
        return "/mobile/mypage/mypage";
    }
}
