package com.icomsys.main_vm.biz.rcp.monitoring.controller;

import com.icomsys.main_vm.biz.common.system.vo.DslDataTableRes;
import com.icomsys.main_vm.biz.rcp.monitoring.service.MonitoringWorkHistoryService;
import com.icomsys.main_vm.biz.rcp.monitoring.vo.InsertWorkHstListVo;
import com.icomsys.main_vm.biz.rcp.monitoring.vo.RetrieveWorkHstListVo;
import com.icomsys.main_vm.biz.rcp.monitoring.vo.SearchWorkHstVo;
import com.icomsys.main_vm.common.code.MenuCategoryVo;
import com.icomsys.main_vm.common.code.MenuVo;
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 org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

import javax.annotation.Resource;
import java.util.List;

@Controller
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/admin/rcp/statistics/monitoring")
public class MonitoringWorkHistoryController {

    @Resource
    MappingJackson2JsonView ajaxMainView;
    private final MonitoringWorkHistoryService monitoringWorkHistoryService;

    @GetMapping("/workhistory/manage.do")
    public String ConversationMarkView(){
        return "/adm/rcp/monitoring/workhistory";
    }

    @PostMapping(value = "/retrieveWorkHst.do")
    @ResponseBody
    public DslDataTableRes<RetrieveWorkHstListVo> retrieveWorkHst(@RequestBody SearchWorkHstVo searchWorkHstVo) {

        QueryResults<RetrieveWorkHstListVo> result = monitoringWorkHistoryService.retrieveWorkHst(searchWorkHstVo);

        return new DslDataTableRes<RetrieveWorkHstListVo>(result);
    }

    @GetMapping("/workhistory/menuList")
    @ResponseBody
    public List<MenuVo>  workhistoryMenuList(){
        return monitoringWorkHistoryService.workhistoryMenuList();
    }

    @GetMapping("/workhistory/menuCategoryList")
    @ResponseBody
    public List<MenuCategoryVo>  workhistoryMenuCategoryList(){
        return monitoringWorkHistoryService.workhistoryMenuCategoryList();
    }

    @PostMapping (value ="/insert/workHst.do")
    @ResponseBody
    public ModelAndView CreateWorkHst(@RequestBody InsertWorkHstListVo insertWorkHstListVo) {

        monitoringWorkHistoryService.createWorkHst(insertWorkHstListVo);

        return new ModelAndView(ajaxMainView);
    }

}
