package com.icomsys.main_vm.biz.common.system.controller;

import com.google.gson.Gson;
import com.icomsys.main_vm.biz.advice.excep.CustomNotFoundException;
import com.icomsys.main_vm.biz.common.login.res.OprmngCodeRes;
import com.icomsys.main_vm.biz.common.system.service.SystemUserAdminService;
import com.icomsys.main_vm.biz.common.system.service.SystemUserService;
import com.icomsys.main_vm.biz.common.system.vo.*;
import com.querydsl.core.QueryResults;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/admin/common/system")
public class SystemUserAdminController {

    private final SystemUserAdminService systemUserAdminService;

    /**
     * @Name 어드민 시스템관리 운영자 관리
     * @Description 사용자 관리와 코멘트 같음.
     * @Author JangWonSeok
     * @CreateDate 2023. 03. 09.
     */
    @GetMapping("/userAdmin/manage.do")
    public String UserAdminView() {
        return "/adm/common/system/userAdmin";
    }

    @PostMapping("/userAdmin/list")
    @ResponseBody
    public DslDataTableRes<SystemBotUserRes> userAdminList(@RequestBody SystemBotUserReq dto) {
        log.info("list dto = {}", new Gson().toJson(dto));
        DslDataTableRes<SystemBotUserRes> result = systemUserAdminService.SystemUserAdminList(dto);
        return result;
    }

    @GetMapping("/userAdmin/view")
    public String userAdminDetailView(@RequestParam(name = "userSeq", required = true) String userSeq) {
        log.info("view Controller - {}", userSeq);
        return "/adm/common/system/userAdminView";
    }


    @GetMapping("/userAdmin/insert")
    public String ServiceGroupInsert() {
        log.info("user insert Controller");
        return "/adm/common/system/userAdminInsert";
    }

    @PostMapping("/userAdmin/save")
    @ResponseBody
    public void userAdminSave(@RequestBody SystemBotUserSaveReq dto) throws CustomNotFoundException {
        log.info("save Dto = {}", new Gson().toJson(dto));
        systemUserAdminService.userAdminSave(dto);
    }

    @PostMapping("/userAdmin/update")
    @ResponseBody
    public void userAdminUpdate(@RequestBody SystemBotUserUpdateReq dto) throws CustomNotFoundException {
        log.info("userUpdatee Dto = {}", new Gson().toJson(dto));
        systemUserAdminService.userAdminUpdate(dto);
    }

    @GetMapping("/userAdmin/authlist")
    @ResponseBody
    public List<SystemBotUserAuthGroupListRes> UserAdminAuthGroupList(@RequestParam(name = "serviceGroup", required = true) String serviceGroup) {
        log.info("UserAuthGroupList=========" + serviceGroup);
        return systemUserAdminService.UserAdminAuthGroupList(serviceGroup);
    }

    @GetMapping("/userAdmin/doubleCheck")
    @ResponseBody
    public String UserAdminDoubleCheck(@RequestParam(name = "userId") String userId) {
        return systemUserAdminService.UserDoubleCheck(userId);
    }

    @GetMapping("/userAdmin/viewData")
    @ResponseBody
    public SystemBotUserViewRes UserAdminViewData(@RequestParam(name = "userSeq", required = true) Long userSeq) throws CustomNotFoundException {
        log.info("UserViewData=========" + userSeq);
        return systemUserAdminService.UserAdminViewData(userSeq);
    }

    @GetMapping("/userAdmin/cust/select")
    @ResponseBody
    public List<SystemBotUserCustRes> UserAdminCustList() throws CustomNotFoundException {

        return systemUserAdminService.UserAdminCustList();
    }

    @GetMapping("/userAdmin/service/select")
    @ResponseBody
    public List<OprmngCodeRes> UserAdminServiceList(@RequestParam(name = "custCode", required = true)String cust) throws CustomNotFoundException {
        return systemUserAdminService.UserAdminServiceList(cust);
    }

}
