package com.cmvr.web.controller.vi;

import com.cmvr.common.core.controller.BaseController;
import com.cmvr.common.core.domain.AjaxResult;
import com.cmvr.common.core.page.TableDataInfo;
import com.cmvr.vi.model.domain.ViCorpus;
import com.cmvr.vi.model.vo.ViContinuousCorpusVO;
import com.cmvr.vi.model.vo.ViCorpusVO;
import com.cmvr.vi.service.IViCorpusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "语音交互--语料库")
@RestController
@RequestMapping("/vi/corpus")
@RequiredArgsConstructor
public class ViCorpusController extends BaseController {

    private final IViCorpusService viCorpusService;

    @ApiOperation("根据id获取语料详细信息")
    @PreAuthorize("@ss.hasPermi('vi:corpus:query')")
    @GetMapping(value = "/{corpusId}")
    public AjaxResult getInfo(@PathVariable("corpusId") Long corpusId) {
        return success(viCorpusService.selectViCorpusByCorpusId(corpusId));
    }

    // ----------------------- 单次对话语料/唤醒语料 --------------------------

    @ApiOperation(value = "查询单次对话语料/唤醒语料列表")
    @PreAuthorize("@ss.hasPermi('vi:corpus:list')")
    @GetMapping("/single/list")
    public TableDataInfo list(ViCorpusVO viCorpusVO) {
        startPage();
        List<ViCorpus> list = viCorpusService.selectViCorpusList(viCorpusVO);
        return getDataTable(list);
    }

    @ApiOperation("新增单次对话语料/唤醒语料")
    @PreAuthorize("@ss.hasPermi('vi:corpus:add')")
    @PostMapping
    public AjaxResult add(@RequestBody ViCorpus viCorpus) {
        return toAjax(viCorpusService.insertViCorpus(viCorpus));
    }

    @ApiOperation("批量新增单次对话语料/唤醒语料")
    @PreAuthorize("@ss.hasPermi('vi:corpus:add')")
    @PostMapping("/insertBatch")
    public AjaxResult insertBatch(@RequestBody List<ViCorpus> data) {
        return toAjax(viCorpusService.insertBatch(data));
    }

    @ApiOperation("删除单次对话语料/唤醒语料")
    @PreAuthorize("@ss.hasPermi('vi:corpus:remove')")
    @DeleteMapping("/{corpusIds}")
    public AjaxResult remove(@PathVariable Long[] corpusIds) {
        return toAjax(viCorpusService.deleteViCorpusByCorpusIds(corpusIds));
    }

    @ApiOperation("修改单次对话语料/唤醒语料")
    @PreAuthorize("@ss.hasPermi('vi:corpus:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody ViCorpus viCorpus) {
        return toAjax(viCorpusService.updateViCorpus(viCorpus));
    }

    // ----------------------- 连续对话 --------------------------

    @ApiOperation("查询连续对话列表")
    @PreAuthorize("@ss.hasPermi('vi:corpus:list')")
    @GetMapping("/continuous/list")
    public TableDataInfo continuousList(ViCorpusVO viCorpusVO) {
        startPage();
        List<ViContinuousCorpusVO> list = viCorpusService.selectContinuousList(viCorpusVO);
        return getDataTable(list);
    }

    @ApiOperation("新增连续对话")
    @PreAuthorize("@ss.hasPermi('vi:corpus:add')")
    @PostMapping("/continuous/insert")
    public AjaxResult add(@RequestBody ViContinuousCorpusVO viContinuousCorpusVO) {
        return toAjax(viCorpusService.insertContinuousViCorpus(viContinuousCorpusVO));
    }

    @ApiOperation("修改连续对话")
    @PreAuthorize("@ss.hasPermi('vi:corpus:edit')")
    @PostMapping("/continuous/update")
    public AjaxResult update(@RequestBody ViContinuousCorpusVO viContinuousCorpusVO) {
        return toAjax(viCorpusService.updateContinuousViCorpus(viContinuousCorpusVO));
    }

    @ApiOperation("删除连续对话")
    @PreAuthorize("@ss.hasPermi('vi:corpus:remove')")
    @DeleteMapping("/continuous")
    public AjaxResult continuousRemove(@RequestBody String[] parentIds) {
        return toAjax(viCorpusService.deleteViCorpusByParentIds(parentIds));
    }
}
