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

import com.google.gson.Gson;
import com.icomsys.main_vm.biz.advice.excep.CustomBadRequestException;
import com.icomsys.main_vm.biz.advice.excep.CustomNotFoundException;
import com.icomsys.main_vm.biz.common.system.vo.DslDataTableRes;
import com.icomsys.main_vm.biz.rcp.conversation.service.ConversationCmmNodeService;
import com.icomsys.main_vm.biz.rcp.conversation.vo.*;
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 java.util.HashMap;

@Controller
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/admin/rcp/conversation")
public class ConversationCmmNodeController {

    private final ConversationCmmNodeService conversationCmmNodeService;

    @GetMapping("/cmmNode/manage.do")
    public String CmmNodeView(){
    return "/adm/rcp/conversation/cmmNode";
    }

    @GetMapping("/cmmNode/cmmNodeEdit.do")
    public ModelAndView cmmNodeEdit(@RequestParam(required = false) String url
                                    , @RequestParam(required = false) String seq
                                    , @RequestParam(required = false) String serviceGroup){
        log.info("url -> {} ", url);
        log.info("seq -> {} ", seq);
        log.info("serviceGroup -> {} ", serviceGroup);
        ModelAndView mv = new ModelAndView();
        mv.setViewName("/adm/rcp/conversation/cmmNodeEdit");
        mv.addObject("url", url);
        mv.addObject("serviceGroup", serviceGroup);
        mv.addObject("seq", seq);
        return mv;
    }

    @PostMapping(value="/selectCmmNodeList")
    @ResponseBody
    public DslDataTableRes<ConversationCmmNodeInfoRes> selectCmmNodeList(@RequestBody ConversationCmmNodeInfoReq dto) throws CustomNotFoundException {
        log.info("dto -> {} ", new Gson().toJson(dto));
        return conversationCmmNodeService.selectCmmNodeList(dto);
    }

    @PostMapping(value = "/selectCmmNode")
    @ResponseBody
    public ConversationCmmNodeDiagramVO selectCmmNode(@RequestBody ConversationCmmNodeEditReq dto) throws CustomNotFoundException {
        log.info("dto -> {} ", new Gson().toJson(dto));
        return conversationCmmNodeService.selectCmmNode(dto);
    }

    @PostMapping(value = "/saveCmmNode")
    @ResponseBody
    public int saveCmmNode(@RequestBody ConversationCmmNodeEditReq dto) throws CustomBadRequestException {
        log.info("dto -> {} ", new Gson().toJson(dto));
        return conversationCmmNodeService.saveCmmNode(dto);
    }

    @PostMapping(value = "/updateCmmNode")
    @ResponseBody
    public int updateCmmNode(@RequestBody ConversationCmmNodeEditReq dto) throws CustomBadRequestException, CustomNotFoundException {
        log.info("dto -> {} ", new Gson().toJson(dto));
        return conversationCmmNodeService.updateCmmNode(dto);
    }

    @PostMapping("/deleteCmmNode")
    @ResponseBody
    public int deleteApiNode(@RequestBody HashMap map){
        log.info("deleteCmmNode -> {} " , new Gson().toJson(map));
        return conversationCmmNodeService.deleteCmmNode(map);
    }

}
