package com.dbnt.sims.authMgt;

import com.dbnt.sims.authMgt.service.AuthMgtService;
import com.dbnt.sims.authMgt.model.AuthMgt;
import com.dbnt.sims.userInfo.service.UserInfoService;
import com.dbnt.sims.userInfo.model.UserInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;


@RestController
@RequiredArgsConstructor
@RequestMapping("/authMgt")
public class AuthMgtController {

  private final UserInfoService userInfoService;
  private final AuthMgtService authMgtService;

  @GetMapping("/authMgtPage")
  public ModelAndView authMgtPage(UserInfo userInfo) {
    ModelAndView mav = new ModelAndView("adminPage/authMgt/authMgt");
    userInfo.setQueryInfo();
    mav.addObject("userInfoList", userInfoService.selectUserInfoList(userInfo));
    userInfo.setContentCnt(userInfoService.selectUserInfoListCnt(userInfo));
    userInfo.setPaginationInfo();
    mav.addObject("searchParams", userInfo);
    return mav;
  }
  
  @GetMapping("/authEditModal")
  public ModelAndView menuEditModal(UserInfo userInfo){
    ModelAndView mav = new ModelAndView("adminPage/authMgt/authEditModal");
    userInfo.setAccessConfigList(authMgtService.selectAccessConfigList(userInfo.getUserSeq(), null));
    userInfo.setApprovalConfigList(authMgtService.selectApprovalConfigList(userInfo.getUserSeq(), null));
    mav.addObject("userInfo", userInfo);
    return mav;
  }

  @PostMapping("/saveAuth")
  public String saveAuth(@RequestBody AuthMgt authMgt){
    authMgtService.saveAuth(authMgt);
    return "";
  }

}
