package incheon.ags.ias.myAuthrtAply.web;

import incheon.ags.ias.myAuthrtAply.service.MyAuthrtAplyService;
import incheon.ags.ias.myAuthrtAply.vo.MyAuthrtAplySearchVO;
import incheon.ags.ias.myAuthrtAply.vo.MyAuthrtAplyVO;
import incheon.ags.ias.user.service.UserService;
import incheon.ags.ias.user.vo.UserVO;
import incheon.com.cmm.context.RequestContext;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;

import java.util.List;
import java.util.Map;

@Controller
@RequiredArgsConstructor
@Slf4j
public class MyAuthrtAplyController {
    private final MyAuthrtAplyService myAuthrtAplyService;
    private final UserService userService;

    @GetMapping("/ags/ias/myAuthrtAply/myAuthrtAplyRegist.do")
    public String myAuthrtAplyRegist(
            @ModelAttribute MyAuthrtAplySearchVO vo,
            ModelMap model) throws Exception {

        // 현재 접속한 사용자 ID 설정
        String currentUserId = RequestContext.getCurrentUserId();


        UserVO userVO = new UserVO();
        userVO.setUserId(currentUserId);
        UserVO userDetail = userService.selectUserDetail(userVO);
        model.addAttribute("userDetail", userDetail);

        MyAuthrtAplyVO myAuthrtAplyVO = new MyAuthrtAplyVO();
        myAuthrtAplyVO.setUserId(currentUserId);
        List<Map<String, Object>> userRoleWithCntList = myAuthrtAplyService.selectSysListWithRoleCnt(myAuthrtAplyVO);
        model.addAttribute("userRoleWithCntList", userRoleWithCntList);

        log.info("시스템 목록: {}", userRoleWithCntList);

        return "/ags/ias/myAuthrtAply/myAuthrtAplyRegist";
    }

}
