package com.microservices.pms.project.controller;

import com.microservices.common.core.web.controller.BaseController;
import com.microservices.common.core.web.domain.AjaxResult;
import com.microservices.common.core.web.page.GenericsTableDataInfo;
import com.microservices.common.log.annotation.Log;
import com.microservices.common.log.enums.BusinessType;
import com.microservices.common.security.annotation.Logical;
import com.microservices.common.security.annotation.RequiresPermissions;
import com.microservices.pms.product.domain.PmsProductRequirementTag;
import com.microservices.pms.product.domain.vo.PmsProductRequirementTagUpdateVo;
import com.microservices.pms.product.service.IPmsProductRequirementTagService;
import com.microservices.pms.project.domain.vo.PmsProjectTestcaseTagInputVo;
import com.microservices.pms.project.domain.vo.PmsProjectTestcaseTagSearchVo;
import com.microservices.pms.utils.PmsConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 测试用例标记Controller
 *
 * @author otto
 * @date 2023-10-10
 */
@RestController
@Api(tags = "项目管理-测试用例标记相关接口")
@RequestMapping("/{enterpriseIdentifier}/pmsProjectTestcaseTag")
public class PmsProjectTestcaseTagController extends BaseController {
    @Autowired
    private IPmsProductRequirementTagService pmsProductRequirementTagService;

    /**
     * 查询测试用例标记列表
     */
    @RequiresPermissions(value = {"pms:pmsProject:show", "pms:pmsProject:showMe", "pms:pmsProjectTestcaseTag:manage"}, logical = Logical.OR)
    @GetMapping("/list")
    @ApiOperation(value = "查询测试用例标记列表")
    public GenericsTableDataInfo<PmsProductRequirementTag> list(
            @Validated PmsProjectTestcaseTagSearchVo pmsProjectTestcaseTagSearchVo
            , @PathVariable String enterpriseIdentifier) {
        startPage();
        return pmsProductRequirementTagService
                .selectPmsProductRequirementTagList(enterpriseIdentifier, pmsProjectTestcaseTagSearchVo.toPmsProductRequirementTag(), PmsConstants.TESTCASE_TAG_AND_MODULE_TYPE);
    }

    /**
     * 获取测试用例标记详细信息
     */
    @RequiresPermissions(value = {"pms:pmsProject:show", "pms:pmsProject:showMe", "pms:pmsProjectTestcaseTag:manage"}, logical = Logical.OR)
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取测试用例标记详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(pmsProductRequirementTagService.selectPmsProductRequirementTagById(id));
    }

    /**
     * 新增测试用例标记
     */
    @RequiresPermissions("pms:pmsProjectTestcaseTag:manage")
    @Log(title = "测试用例标记", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增测试用例标记")
    public AjaxResult add(@RequestBody @Validated PmsProjectTestcaseTagInputVo pmsProjectTestcaseTagInputVo) {
        return toAjax(pmsProductRequirementTagService.insertPmsProductRequirementTag(pmsProjectTestcaseTagInputVo.toPmsProductRequirementTag(), PmsConstants.TESTCASE_TAG_AND_MODULE_TYPE));
    }

    /**
     * 修改测试用例标记
     */
    @RequiresPermissions("pms:pmsProjectTestcaseTag:manage")
    @Log(title = "测试用例标记", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改测试用例标记")
    public AjaxResult edit(@RequestBody @Validated PmsProductRequirementTagUpdateVo pmsProductRequirementTagUpdateVo) {
        return toAjax(pmsProductRequirementTagService.updatePmsProductRequirementTag(pmsProductRequirementTagUpdateVo.toPmsProductRequirementTag()));
    }

    /**
     * 删除测试用例标记
     */
    @RequiresPermissions("pms:pmsProjectTestcaseTag:manage")
    @Log(title = "测试用例标记", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除测试用例标记")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(pmsProductRequirementTagService.deletePmsProductRequirementTagByIds(ids));
    }
}
