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.rcp.conversation.service.ConversationApiNodeEditService;
import com.icomsys.main_vm.biz.rcp.conversation.vo.ConversationApiNodeEditReq;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;

/**
 * Name : ConversationApiNodeEdit
 * date : 2023-02-02
 * author : Mong
 * description :
 * ===========================================================
 * DATE                 AUTHOR                NOTE
 * -----------------------------------------------------------
 * 2023-02-02                Mong             최초 생성
 */

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

    private final ConversationApiNodeEditService conversationApiNodeEditService;
    @GetMapping("/apiNodeEdit/manage.do")
    public ModelAndView apiNodeEditManage(@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/apiNodeEdit");
        mv.addObject("url", url);
        mv.addObject("serviceGroup", serviceGroup);
        mv.addObject("seq", seq);
        return mv;
    }

    @PostMapping("/insertApiNode")
    @ResponseBody
    public int insertApiNode(@RequestBody ConversationApiNodeEditReq dto) throws CustomBadRequestException{
        log.info("data -> {} " , new Gson().toJson(dto));
//        return 0;
        return conversationApiNodeEditService.insertApiNode(dto);
    }

    @PostMapping("/updateApiNode")
    @ResponseBody
    public int updateApiNode(@RequestBody ConversationApiNodeEditReq dto) throws CustomBadRequestException {
        log.info("updateData -> {} " , new Gson().toJson(dto));
        return conversationApiNodeEditService.updateApiNode(dto);
    }

    @PostMapping("/selectApiNode")
    @ResponseBody
    public HashMap selectApiNode(@RequestBody HashMap map){
        log.info("selectApiNode -> {} " , map);
        return conversationApiNodeEditService.selectApiNode(map);
    }
}
