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.ViScheme;
import com.cmvr.vi.service.IViSchemeService;
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/scheme")
@RequiredArgsConstructor
public class ViSchemeController extends BaseController {
    private final IViSchemeService viSchemeService;

    @ApiOperation("查询方案列表")
    @PreAuthorize("@ss.hasPermi('vi:scheme:list')")
    @GetMapping("/list")
    public TableDataInfo list(ViScheme viScheme) {
        startPage();
        List<ViScheme> list = viSchemeService.selectViSchemeList(viScheme);
        return getDataTable(list);
    }

    @ApiOperation("根据ID查询方案详细信息")
    @PreAuthorize("@ss.hasPermi('vi:scheme:query')")
    @GetMapping(value = "/{schemeId}")
    public AjaxResult getInfo(@PathVariable("schemeId") String schemeId) {
        return success(viSchemeService.selectViSchemeBySchemeId(schemeId));
    }

    @ApiOperation("新增方案")
    @PreAuthorize("@ss.hasPermi('vi:scheme:add')")
    @PostMapping
    public AjaxResult add(@RequestBody ViScheme viScheme) {
        return toAjax(viSchemeService.insertViScheme(viScheme));
    }

    @ApiOperation("修改方案")
    @PreAuthorize("@ss.hasPermi('vi:scheme:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody ViScheme viScheme) {
        return toAjax(viSchemeService.updateViScheme(viScheme));
    }

    @ApiOperation("删除方案")
    @PreAuthorize("@ss.hasPermi('vi:scheme:remove')")
    @DeleteMapping("/{schemeIds}")
    public AjaxResult remove(@PathVariable String[] schemeIds) {
        return toAjax(viSchemeService.deleteViSchemeBySchemeIds(schemeIds));
    }
}
