package com.microservices.pms.product.controller;

import com.microservices.common.core.web.controller.BaseController;
import com.microservices.common.core.web.domain.AjaxResult;
import com.microservices.common.core.web.domain.GenericsAjaxResult;
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.RequiresPermissions;
import com.microservices.pms.product.domain.vo.*;
import com.microservices.pms.product.service.IPmsProductRequirementService;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 产品用户需求相关接口
 *
 * @author otto
 * @date 2023-10-10
 */
@RestController
@Api(tags = "项目管理-用户需求相关接口")
@RequestMapping("/{enterpriseIdentifier}/productUserRequirement")
@ApiImplicitParams({
        @ApiImplicitParam(name = "enterpriseIdentifier", value = "企业标识", paramType = "path", dataType = "String")
})
public class ProductUserReqController extends BaseController {
    @Autowired
    private IPmsProductRequirementService pmsProductRequirementService;

    /**
     * 查询产品用户需求列表
     */
    @ApiOperation(value = "查询用户需求列表")
    @RequiresPermissions("pms:pmsProduct:show")
    @GetMapping("/list")
    public GenericsTableDataInfo<ProductUserReqDataVo> list(@Validated ProductUserReqSearchVo productUserReqSearchVo) {
        return pmsProductRequirementService.selectUserReqList(productUserReqSearchVo);
    }

    /**
     * 获取用户需求详细信息
     */
    @RequiresPermissions("pms:pmsProduct:show")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取用户需求详细信息")
    public GenericsAjaxResult<ProductUserReqDetailVo> getInfo(@PathVariable("id") Long id) {
        return genericsSuccess(pmsProductRequirementService.selectUserReqDetailById(id));
    }

    /**
     * 新增用户需求
     */
    @RequiresPermissions("pms:pmsProductRequirement:add")
    @Log(title = "用户需求", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增用户需求")
    public AjaxResult add(@PathVariable String enterpriseIdentifier,
                          @RequestBody @Validated ProductUserReqInputVo productUserReqInputVo) {
        productUserReqInputVo.setEnterpriseIdentifier(enterpriseIdentifier);
        return success(pmsProductRequirementService.insertUserReq(productUserReqInputVo));
    }

    /**
     * 修改用户需求
     */
    @RequiresPermissions("pms:pmsProductRequirement:edit")
    @Log(title = "用户需求", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改用户需求")
    public AjaxResult edit(@RequestBody @Validated ProductUserReqUpdateVo productUserReqUpdateVo) {
        return toAjax(pmsProductRequirementService.updateUserReq(productUserReqUpdateVo));
    }

    /**
     * 删除用户需求
     */
    @RequiresPermissions("pms:pmsProductRequirement:remove")
    @Log(title = "用户需求", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除用户需求")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(pmsProductRequirementService.deleteUserReqByIds(ids));
    }

    /**
     * 评审用户需求
     */
    @RequiresPermissions("pms:pmsProductRequirement:edit")
    @Log(title = "用户需求", businessType = BusinessType.UPDATE)
    @PutMapping("/review")
    @ApiOperation(value = "评审用户需求")
    public AjaxResult review(@RequestBody @Validated ProductReqReviewVo productReqReviewVo) {
        return toAjax(pmsProductRequirementService.reviewUserReq(productReqReviewVo));
    }

    /**
     * 查询用户需求状态列表
     */
    @ApiOperation(value = "查询用户需求状态列表")
    @RequiresPermissions("pms:pmsProduct:show")
    @GetMapping("/statusList")
    public List<ReqStatusCommonVo> statusList() {
        return pmsProductRequirementService.selectUserReqStatusList();
    }
}
