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.rcp.conversation.service.ConversationScenarioGUIService;
import com.icomsys.main_vm.biz.rcp.conversation.vo.ConversationScenarioDiagramRes;
import com.icomsys.main_vm.biz.rcp.conversation.vo.ConversationScenarioDiagramVO;
import com.icomsys.main_vm.biz.rcp.conversation.vo.ConversationScenarioMasterVO;
import com.icomsys.main_vm.biz.rcp.conversation.vo.LongtextManagerVO;
import com.icomsys.main_vm.db.jpa.entity.scenario.id.TbLongtextManagerId;
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;

/**
 * Name : ConversationScenarioGUINodeEditController
 * date : 2023-02-03
 * author : Mong
 * description :
 * ===========================================================
 * DATE                 AUTHOR                NOTE
 * -----------------------------------------------------------
 * 2023-02-03                Mong             최초 생성
 */
@Controller
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/admin/rcp/conversation")
public class ConversationScenarioGUINodeEditController {

    private final ConversationScenarioGUIService conversationScenarioGUIService;

    @GetMapping("/scenarioGUINodeEdit.do")
    public ModelAndView scenarioGUINodeEdit(@RequestParam String flag, @RequestParam Long seq, @RequestParam String custCode, @RequestParam String serviceGroup){
        log.info("flag, seq, custCode, serviceGroup -> {} ", flag, seq);
        ModelAndView mv = new ModelAndView();
        mv.setViewName("/adm/rcp/conversation/scenarioGUINodeEdit");
        mv.addObject("flag", flag);
        mv.addObject("seq", seq);
        mv.addObject("custCode", custCode);
        mv.addObject("serviceGroup", serviceGroup);
        return mv;
    }

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

    @PostMapping(value = "/insertScenario")
    @ResponseBody
    public int insertDev(@RequestBody LongtextManagerVO dto) {
        log.info("dto -> {} ", new Gson().toJson(dto));
        return conversationScenarioGUIService.insertDev(dto);
    }

    @PostMapping(value = "/selectScenario")
    @ResponseBody
    public LongtextManagerVO selectDev(@RequestBody TbLongtextManagerId dto) throws CustomNotFoundException {
        log.info("dto -> {} ", new Gson().toJson(dto));
        if (dto.getRfSeq() == null) {
            dto.setRfSeq(0L);
        }
        return conversationScenarioGUIService.selectDev(dto);
    }


    @PostMapping(value = "/scenario/select/diagram")
    @ResponseBody
    public ConversationScenarioDiagramRes selectDiagram(@RequestBody ConversationScenarioMasterVO dto) throws CustomNotFoundException, CustomBadRequestException {
        log.info("dto -> {} ", new Gson().toJson(dto));
        return conversationScenarioGUIService.selectScenarioDiagram(dto);
    }

    @PostMapping(value = "/scenario/save/diagram")
    @ResponseBody
    public int saveScenarioDiagram(@RequestBody ConversationScenarioDiagramVO dto) throws CustomBadRequestException, CustomNotFoundException {
        log.info("dto -> {} ", new Gson().toJson(dto));

        return conversationScenarioGUIService.saveScenarioDiagram(dto);
    }

    @GetMapping(value = "/scenario/test/contents")
    @ResponseBody
    public LongtextManagerVO selectTestContents(@RequestParam String masterSeq) throws CustomBadRequestException, CustomNotFoundException {
        return conversationScenarioGUIService.selectTestContents(masterSeq);
    }
}

