package com.test.test.controller;

import com.test.common.annotation.Log;
import com.test.common.core.controller.BaseController;
import com.test.common.core.domain.AjaxResult;
import com.test.common.core.page.TableDataInfo;
import com.test.common.enums.BusinessType;
import com.test.test.domain.TestPlan;
import com.test.test.domain.qo.IDQO;
import com.test.test.domain.qo.TestPlanAddQO;
import com.test.test.domain.qo.TestPlanListQO;
import com.test.test.domain.vo.TestPlanListVO;
import com.test.test.service.ITestPlanService;
import jakarta.annotation.Resource;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试计划controller
 */
@Slf4j
@RestController
@RequestMapping("/test/testPlan")
public class TestPlanController extends BaseController {


    @Resource
    private ITestPlanService testPlanService;

    /**
     * 查询测试计划列表
     */
    @GetMapping("/testPlanList")
    public TableDataInfo planList(@Validated TestPlanListQO qo) {
        startPage();
        List<TestPlanListVO> list = testPlanService.getPlanList(qo);
        return getDataTable(list);
    }

    /**
     * 新增测试计划
     */
    @Log(title = "测试计划", businessType = BusinessType.INSERT)
    @PostMapping("/addPlan")
    public AjaxResult addPlan(@RequestBody TestPlanAddQO testPlanAddQO) {
        return toAjax(testPlanService.insertTestPlan(testPlanAddQO));
    }

    /**
     * 删除测试计划
     */
    @Log(title = "测试计划", businessType = BusinessType.DELETE)
    @PostMapping("/deletePlan")
    public AjaxResult deletePlan(@RequestBody IDQO qo) {
        TestPlan testPlan = testPlanService.selectTestPlanById(qo.getId());
        testPlan.setDelFlag("1");
        return toAjax(testPlanService.updateTestPlan(testPlan));
    }

    /**
     * 获取测试计划详细信息
     */
    @PostMapping("/planDetail")
    public AjaxResult getInfo(@RequestBody IDQO qo) {
        return success(testPlanService.selectTestPlanById(qo.getId()));
    }

    /**
     * 修改测试计划
     */
    @Log(title = "测试计划", businessType = BusinessType.UPDATE)
    @PostMapping("/updatePlan")
    public AjaxResult edit(@RequestBody TestPlan testPlan) {
        return toAjax(testPlanService.updateTestPlan(testPlan));
    }
}
