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

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.icomsys.main_vm.biz.advice.excep.CustomBadRequestException;
import com.icomsys.main_vm.biz.rcp.conversation.service.ConversationSystemEntityService;
import com.icomsys.main_vm.biz.rcp.conversation.vo.SystemEntityRes;
import com.icomsys.main_vm.db.jpa.entity.conversation.TbEntityMaster;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpMethod;
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 javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.icomsys.main_vm.biz.rcp.conversation.nlp.wisenut.util.RestTemplateUtil.callNlpApi;

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

    private final ConversationSystemEntityService conversationSystemEntityService;

    @Resource
    MappingJackson2JsonView ajaxMainView;

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


    /**
     * @Name synchronizeEntity
     * @Description 시스템 엔티티 동기화
     * @Author 장동희
     * @CreateDate 2023. 3. 17.
     */
    @RequestMapping(value = "/systemEntity/synchronize.do", method = RequestMethod.POST)
    @ResponseBody
    public ModelAndView synchronizeEntity(HttpServletRequest request) {

        return conversationSystemEntityService.synchronizeEntityList(request);
    }

    @GetMapping("/scenario/systemEntity/list")
    @ResponseBody
    public List<SystemEntityRes> SystemEntityList() {

        return  conversationSystemEntityService.SystemEntityList();
    }

    @PostMapping("/scenario/systemEntity/search")
    @ResponseBody
    public ModelAndView selectSystemEntityList() {
        ModelAndView mv = new ModelAndView(ajaxMainView);
        mv.addObject("list", conversationSystemEntityService.SystemEntityList());
        return mv;
    }
}
