package com.dbnt.faisp.config;

import com.dbnt.faisp.codeMgt.service.CodeMgtService;
import com.dbnt.faisp.menuMgt.model.MenuMgt;
import com.dbnt.faisp.menuMgt.service.MenuMgtService;
import com.dbnt.faisp.userInfo.model.UserInfo;
import com.dbnt.faisp.userInfo.service.UserInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;


@RestController
@RequiredArgsConstructor
@RequestMapping("/modal")
public class ModalController {

  private final MenuMgtService menuMgtService;
  private final UserInfoService userInfoService;
  private final CodeMgtService codeMgtService;

  @GetMapping("/menuModal")
  public ModelAndView menuModalPage(@AuthenticationPrincipal UserInfo loginUser, MenuMgt menuMgt){
    ModelAndView mav = new ModelAndView("commonModal/menuModal");
    menuMgt.setUserSeq(loginUser.getUserSeq());
    menuMgt.setQueryInfo();
    mav.addObject("menuMgtList", menuMgtService.selectMenuMgtListToAccessAuth(menuMgt));
    menuMgt.setContentCnt(menuMgtService.selectMenuMgtListToAccessAuthCnt(menuMgt));
    menuMgt.setPaginationInfo();
    mav.addObject("searchParams", menuMgt);
    return mav;
  }

  @GetMapping("/userModal")
  public ModelAndView userMoadlPage(@AuthenticationPrincipal UserInfo loginUser, UserInfo userInfo){
    ModelAndView mav = new ModelAndView("commonModal/userModal");
    userInfo.setQueryInfo();
    if(userInfo.getUserStatus() == null || userInfo.getUserStatus().equals("")) {
      userInfo.setUserStatus("USC003");
    }
    mav.addObject("OgList", codeMgtService.selectCodeMgtList("OG"));
    mav.addObject("OfcList", codeMgtService.selectCodeMgtList("OFC"));
    mav.addObject("userInfoList", userInfoService.selectUserInfoList(userInfo));
    userInfo.setContentCnt(userInfoService.selectUserInfoListCnt(userInfo));
    userInfo.setPaginationInfo();
    mav.addObject("searchParams", userInfo);
    return mav;
  }
}
