package com.dbnt.faisp.userInfo;

import com.dbnt.faisp.authMgt.service.AuthMgtService;
import com.dbnt.faisp.codeMgt.service.CodeMgtService;
import com.dbnt.faisp.menuMgt.service.MenuMgtService;
import com.dbnt.faisp.userInfo.service.UserInfoService;
import com.dbnt.faisp.userInfo.model.UserInfo;
import lombok.RequiredArgsConstructor;

import java.util.List;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;


@RestController
@RequiredArgsConstructor
@RequestMapping("/userMgt")
public class userMgtController {

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

  @GetMapping("/userMgtPage")
  public ModelAndView codeMgtPage(UserInfo userInfo) {
    ModelAndView mav = new ModelAndView("adminPage/userMgt/userMgt");
    userInfo.setQueryInfo();
    if(userInfo.getUserStatus() == "" || userInfo.getUserStatus() == null) {
    	userInfo.setUserStatus("USC003");
    }
    mav.addObject("userInfoList", userInfoService.selectUserInfoList(userInfo));
    userInfo.setContentCnt(userInfoService.selectUserInfoListCnt(userInfo));
    userInfo.setPaginationInfo();
    mav.addObject("searchParams", userInfo);
    return mav;
  }

  @GetMapping("/userEditModal")
  public ModelAndView menuEditModal(UserInfo userInfo){
    ModelAndView mav = new ModelAndView("adminPage/userMgt/userEditModal");
    mav.addObject("OgList", codeMgtService.selectCodeMgtList("OG"));
    mav.addObject("OfcList", codeMgtService.selectCodeMgtList("OFC"));
    mav.addObject("userInfo", userInfoService.selectUserInfo(userInfo.getUserSeq()));
    return mav;
  }
  
  @PostMapping("/userApproval")
  @ResponseBody
  public int userApproval(@RequestBody List<UserInfo> userInfo){
	 int result = userInfoService.updateUserApproval(userInfo);
    return result;
  }
  
  @PostMapping("/userCompanion")
  @ResponseBody
  public int userCompanion(@RequestBody List<UserInfo> userInfo){
	 int result = userInfoService.updateUserCompanion(userInfo);
    return result;
  }
  
  @PostMapping("/updateUserInfo")
  public void updateUserInfo(UserInfo userInfo) {
	  userInfoService.updateUser(userInfo);
  }
  
  @PostMapping("/userDelete")
  @ResponseBody
  public void userDelete(@RequestBody List<UserInfo> userInfo) {
	  userInfoService.userDelete(userInfo);  
  }

}
