package com.microservices.pms.product.controller;

import com.alibaba.fastjson2.JSONObject;
import com.microservices.common.core.web.controller.BaseController;
import com.microservices.common.core.web.domain.GenericsAjaxResult;
import com.microservices.common.core.web.page.GenericsTableDataInfo;
import com.microservices.common.security.annotation.RequiresPermissions;
import com.microservices.pms.product.domain.vo.ProductReqOperationRecordDataVo;
import com.microservices.pms.product.domain.vo.ProductReqSpecsAssociatedTestcaseDataVo;
import com.microservices.pms.product.service.IPmsProductReqOperationRecordService;
import com.microservices.pms.product.service.IPmsProductRequirementService;
import com.microservices.pms.project.service.IPmsProjectTestcaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 产品需求规格相关接口
 *
 * @author otto
 * @date 2023-10-10
 */
@RestController
@Api(tags = "项目管理-需求跟踪相关接口")
@RequestMapping("/{enterpriseIdentifier}/productRequirementTracking")
@ApiImplicitParams({
        @ApiImplicitParam(name = "enterpriseIdentifier", value = "企业标识", paramType = "path", dataType = "String")
})
public class ProductReqTrackingController extends BaseController {
    @Autowired
    private IPmsProductReqOperationRecordService pmsProductReqOperationRecordService;
    @Autowired
    private IPmsProjectTestcaseService pmsProjectTestcaseService;
    @Autowired
    private IPmsProductRequirementService pmsProductRequirementService;

    /**
     * 查询用户需求变更记录
     */
    @ApiOperation(value = "查询用户需求变更记录")
    @RequiresPermissions("pms:pmsProduct:show")
    @GetMapping("/{userReqId}/userReqChangeRecord")
    public GenericsTableDataInfo<ProductReqOperationRecordDataVo> getUserReqChangeRecordList(
            @PathVariable("userReqId") Long userReqId) {
        return getGenericsDataTable(pmsProductReqOperationRecordService.selectUserReqChangeRecordList(userReqId));
    }

    /**
     * 查询用户需求变更记录
     */
    @ApiOperation(value = "查询需求规格变更记录")
    @RequiresPermissions("pms:pmsProduct:show")
    @GetMapping("/{reqSpecsId}/reqSpecsChangeRecord")
    public GenericsTableDataInfo<ProductReqOperationRecordDataVo> getReqSpecsChangeRecordList(
            @PathVariable("reqSpecsId") Long reqSpecsId) {
        return getGenericsDataTable(pmsProductReqOperationRecordService.selectReqSpecsChangeRecordList(reqSpecsId));
    }

    @ApiOperation(value = "查询需求规格关联的测试用例")
    @RequiresPermissions("pms:pmsProduct:show")
    @GetMapping("/{reqSpecsId}/associatedTestcase")
    public GenericsTableDataInfo<ProductReqSpecsAssociatedTestcaseDataVo> getReqSpecsAssociatedTestcaseList(
            @PathVariable("reqSpecsId") Long reqSpecsId) {
        return getGenericsDataTable(pmsProjectTestcaseService.selectReqSpecsAssociatedTestcaseList(reqSpecsId));
    }

    @ApiOperation(value = "查询需求规格关联的计划")
    @RequiresPermissions("pms:pmsProduct:show")
    @GetMapping("/{reqSpecsId}/associatedPlan")
    public GenericsAjaxResult<JSONObject> getReqSpecsAssociatedPlanData(
            @PathVariable("reqSpecsId") Long reqSpecsId) {
        return GenericsAjaxResult.success(pmsProductRequirementService.selectReqSpecsAssociatedPlanData(reqSpecsId));
    }
}
