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

import com.icomsys.main_vm.biz.common.login.res.UserVo;
import com.icomsys.main_vm.biz.common.system.vo.DslDataTableRes;
import com.icomsys.main_vm.biz.common.system.vo.SystemCommoncodeReq;
import com.icomsys.main_vm.biz.common.system.vo.SystemCommoncodeRes;
import com.icomsys.main_vm.biz.rcp.learningTest.service.LearningTestInTtsService;
import com.icomsys.main_vm.db.jpa.entity.system.TbBotCommonCode;
import com.icomsys.main_vm.db.jpa.repo.system.TbBotCommonCodeRepo;
import com.icomsys.main_vm.db.mybatis.alias.LoginVO;
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.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/admin/rcp/learningTest")
public class LearningTestInTtsController {

    private final TbBotCommonCodeRepo tbBotCommonCodeRepo;
    private final MappingJackson2JsonView ajaxMainView;
    private final LearningTestInTtsService learningTestInTtsService;

    @GetMapping("/ttstest/manage.do")
    public String ttstest(){
        return "/adm/rcp/learningTest/ttstest";
    }


    @ResponseBody
    @RequestMapping(value = "/ttstest/ttsproduct.do",method = RequestMethod.GET)
    public DslDataTableRes<SystemCommoncodeRes> ttsProduct(HttpServletRequest request, @RequestParam String custCode, String serviceGroup) {

        LoginVO resultVO = (LoginVO) request.getSession().getAttribute("LoginVO");
        UserVo userVo = new UserVo();
        userVo.setRoleVal(resultVO.getAuthCode());
        SystemCommoncodeReq dto = new SystemCommoncodeReq();
        dto.setUserVo(userVo);
        dto.setServiceGroup(serviceGroup);
        dto.setOprmngCode(custCode + "_RCP_" + serviceGroup);
        dto.setCodeType("TTS_PRODUCT");
        QueryResults<SystemCommoncodeRes> result = tbBotCommonCodeRepo.SystemCommoncodeProductList(dto);

        return new DslDataTableRes<SystemCommoncodeRes>(result);
    }

    @RequestMapping(value = "/ttstest/play.do",method = RequestMethod.POST)
    @ResponseBody
    public ModelAndView ttsTest(@RequestBody Map<String, String> tMap) {
        ModelAndView mv = new ModelAndView(ajaxMainView);
        String path = learningTestInTtsService.ttsTestApi(tMap);
        mv.addObject("path",path);
        return mv;
    }

}
