package com.madeu.controller.mobile.mobileuserphysical;

import com.madeu.constants.Constants;
import com.madeu.init.ManagerDraftAction;
import com.madeu.service.mobile.mobileuserphysical.MobileUserPhysicalService;
import com.madeu.service.web.webloghistory.WebLogHistoryService;
import com.madeu.service.web.webuser.WebUserService;
import com.madeu.util.HttpUtil;
import com.madeu.util.RequestLogUtil;
import com.madeu.view.web.WebUserAgreementView;
import com.madeu.view.web.WebUserPhysicalView;
import com.madeu.view.web.WebUserView;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
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 org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;

@Slf4j
@Controller
public class MobileUserPhysicalController extends ManagerDraftAction {

    @Autowired
    private MobileUserPhysicalService mobileUserPhysicalService;

    /**
     * 인바디정보 리스트 화면으로 이동.
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/mobileuserphysical/selectListUserPhysicalIntro.do")
    public String selectListUserPhysicalIntro(HttpSession session, HttpServletRequest request, HttpServletResponse response, Model model) {
        log.debug("MobileUserPhysicalController  selectListUserPhysicalIntro 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 {
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            return "/web/login/logout";
        }
        log.debug("MobileUserPhysicalController  selectListUserIntro END");
        return "/mobile/userPhysical/selectListUserPhysical";
    }

    /**
     * 고객 신체정보 리스트 조회
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/mobileuserphysical/selectUserPhysicalList.do")
    public ModelAndView selectUserPhysicalList(HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        log.debug("WebCustomerController selectUserPhysicalList START");

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

        try {
            if (!mobileCheckLogin(session)) {
                return null;
            } else {
                paramMap.put("muUserId", String.valueOf(session.getAttribute("loginUserId")));
                paramMap.put("loginUserId", String.valueOf(session.getAttribute("loginUserId")));
                map = mobileUserPhysicalService.selectUserPhysicalList(paramMap);
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            return null;
        } finally {
            if (Constants.OK == map.get("msgCode")) {

            } else {
                map.put("msgCode", Constants.FAIL);
                map.put("success", false);
                if (null == map.get("msgDesc") || ("").equals(map.get("msgDesc"))) {
                    map.put("msgDesc", "정상적으로 수행되지 않았습니다. 관리자에게 문의하시기 바랍니다.");
                }
            }
        }
        log.debug("MobileUserPhysicalController selectUserPhysicalList END");
        return HttpUtil.makeHashToJsonModelAndView(map);
//            return map;
    }

    /**
     * 고객 최신 Bmi 정보 리스트 조회
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/mobileuserphysical/selectRecentUserPhysicalList.do")
    public ModelAndView selectRecentUserPhysicalList(HttpSession session, HttpServletRequest request, HttpServletResponse response) {

        log.debug("WebCustomerController selectRecentUserPhysicalList START");

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

        try {
            if (!mobileCheckLogin(session)) {
                return null;
            } else {
                paramMap.put("muUserId", String.valueOf(session.getAttribute("loginUserId")));
                paramMap.put("loginUserId", String.valueOf(session.getAttribute("loginUserId")));
                map = mobileUserPhysicalService.selectRecentUserPhysicalList(paramMap);
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            return null;
        } finally {
            if (Constants.OK == map.get("msgCode")) {

            } else {
                map.put("msgCode", Constants.FAIL);
                map.put("success", false);
                if (null == map.get("msgDesc") || ("").equals(map.get("msgDesc"))) {
                    map.put("msgDesc", "정상적으로 수행되지 않았습니다. 관리자에게 문의하시기 바랍니다.");
                }
            }
        }
        log.debug("MobileUserPhysicalController selectRecentUserPhysicalList END");
        return HttpUtil.makeHashToJsonModelAndView(map);
    }
}