package com.cmvr.web.controller.aima;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.cmvr.common.annotation.Log;
import com.cmvr.common.core.controller.BaseController;
import com.cmvr.common.core.domain.AjaxResult;
import com.cmvr.common.enums.BusinessType;
import com.cmvr.aima.domain.AimaTestCase;
import com.cmvr.aima.domain.vo.AimaTestCaseVo;
import com.cmvr.aima.service.IAimaTestCaseService;
import com.cmvr.common.utils.poi.ExcelUtil;
import com.cmvr.common.core.page.TableDataInfo;

@RestController
@RequestMapping("/aima/testcase")
@Api(tags = "爱玛电动车--测试用例管理")
public class AimaTestCaseController extends BaseController {
    @Autowired
    private IAimaTestCaseService aimaTestCaseService;

    @ApiOperation("查询测试用例列表")
    @PreAuthorize("@ss.hasPermi('aima:testcase:list')")
    @GetMapping("/list")
    public TableDataInfo list(AimaTestCase aimaTestCase) {
        startPage();
        List<AimaTestCaseVo> list = aimaTestCaseService.selectAimaTestCaseVoList(aimaTestCase);
        return getDataTable(list);
    }

    @ApiOperation("导出测试用例列表")
    @PreAuthorize("@ss.hasPermi('aima:testcase:export')")
    @Log(title = "测试用例管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AimaTestCase aimaTestCase) {
        List<AimaTestCaseVo> list = aimaTestCaseService.selectAimaTestCaseVoList(aimaTestCase);
        ExcelUtil<AimaTestCaseVo> util = new ExcelUtil<>(AimaTestCaseVo.class);
        util.exportExcel(response, list, "测试用例数据");
    }

    @ApiOperation("获取测试用例详细信息")
    @PreAuthorize("@ss.hasPermi('aima:testcase:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(aimaTestCaseService.selectAimaTestCaseById(id));
    }

    @ApiOperation("新增测试用例")
    @PreAuthorize("@ss.hasPermi('aima:testcase:add')")
    @Log(title = "测试用例管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AimaTestCase aimaTestCase) {
        return toAjax(aimaTestCaseService.insertAimaTestCase(aimaTestCase));
    }

    @ApiOperation("修改测试用例")
    @PreAuthorize("@ss.hasPermi('aima:testcase:edit')")
    @Log(title = "测试用例管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AimaTestCase aimaTestCase) {
        return toAjax(aimaTestCaseService.updateAimaTestCase(aimaTestCase));
    }

    @ApiOperation("删除测试用例")
    @PreAuthorize("@ss.hasPermi('aima:testcase:remove')")
    @Log(title = "测试用例管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(aimaTestCaseService.deleteAimaTestCaseByIds(ids));
    }
}
