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.test.model.vo.TeTaskExecuteProjectVO;
import com.cmvr.vi.model.domain.ViProject;
import com.cmvr.vi.service.IViProjectService;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "语音交互--项目管理")
@RestController
@RequestMapping("/vi/project")
@RequiredArgsConstructor
public class ViProjectController extends BaseController {

    private final IViProjectService viProjectService;

    @ApiOperation("获取项目列表")
    @PreAuthorize("@ss.hasPermi('vi:project:list')")
    @GetMapping("/list")
    public TableDataInfo list(ViProject viProject) {
        startPage();
        List<ViProject> list = viProjectService.selectViProjectList(viProject);
        return getDataTable(list);
    }

    @ApiOperation("根据id获取项目信息")
    @PreAuthorize("@ss.hasPermi('vi:project:query')")
    @GetMapping(value = "/{projectId}")
    public AjaxResult getInfo(@PathVariable("projectId") String projectId) {
        return success(viProjectService.selectViProjectByProjectId(projectId));
    }

    @ApiOperation("添加项目")
    @PreAuthorize("@ss.hasPermi('vi:project:add')")
    @PostMapping
    public AjaxResult add(@RequestBody ViProject viProject) {
        return toAjax(viProjectService.insertViProject(viProject));
    }

    @ApiOperation("编辑项目")
    @PreAuthorize("@ss.hasPermi('vi:project:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody ViProject viProject) {
        return toAjax(viProjectService.updateViProject(viProject));
    }

    @ApiOperation("删除项目")
    @PreAuthorize("@ss.hasPermi('vi:project:remove')")
    @DeleteMapping("/{projectIds}")
    public AjaxResult remove(@PathVariable String[] projectIds) {
        return toAjax(viProjectService.deleteViProjectByProjectIds(projectIds));
    }

    @ApiOperation("查询项目执行时运行参数")
    @GetMapping("/queryExecuteRunParams")
    public AjaxResult queryExecuteRunParams(@RequestParam("projectId") String projectId) {
        return AjaxResult.ok(viProjectService.queryExecuteRunParams(projectId));
    }

    @ApiOperation("执行项目")
    @PostMapping("/execute")
    public AjaxResult execute(@RequestBody TeTaskExecuteProjectVO taskExecuteProjectVO) {
        return AjaxResult.ok(viProjectService.executeProject(taskExecuteProjectVO));
    }

    @ApiOperation("查询最近一次项目执行实例id")
    @GetMapping("/queryExecuteInstId/{projectId}")
    public AjaxResult queryExecuteInstId(@PathVariable("projectId") String projectId) {
        return AjaxResult.ok(viProjectService.queryExecuteInstId(projectId));
    }

    @ApiOperation("评估查询")
    @GetMapping("/evaluation/{projectId}")
    public AjaxResult queryEvaluation(@PathVariable("projectId") String projectId) {
        return AjaxResult.ok(viProjectService.queryEvaluation(projectId));
    }
}
