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}/productRequirementSpecs")
@ApiImplicitParams({
        @ApiImplicitParam(name = "enterpriseIdentifier", value = "企业标识", paramType = "path", dataType = "String")
})
public class ProductReqSpecsController extends BaseController {
    @Autowired
    private IPmsProductRequirementService pmsProductRequirementService;

    /**
     * 查询产品需求规格列表
     */
    @ApiOperation(value = "查询需求规格列表")
    @RequiresPermissions("pms:pmsProduct:show")
    @GetMapping("/list")
    public GenericsTableDataInfo<ProductReqSpecsDataVo> list(@PathVariable String enterpriseIdentifier, @Validated ProductReqSpecsSearchVo productReqSpecsSearchVo) {
        return pmsProductRequirementService.selectReqSpecsList(productReqSpecsSearchVo);
    }

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

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

    /**
     * 修改需求规格
     */
    @RequiresPermissions("pms:pmsProductRequirement:edit")
    @Log(title = "需求规格", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改需求规格")
    public AjaxResult edit(@RequestBody @Validated ProductReqSpecsUpdateVo productReqSpecsUpdateVo) {
        return toAjax(pmsProductRequirementService.updateReqSpecs(productReqSpecsUpdateVo));
    }

    /**
     * 变更需求规格
     */
    @RequiresPermissions("pms:pmsProductRequirement:edit")
    @Log(title = "需求规格", businessType = BusinessType.UPDATE)
    @PutMapping("/change")
    @ApiOperation(value = "变更需求规格")
    public AjaxResult change(@RequestBody @Validated ProductReqSpecsChangeVo productReqSpecsChangeVo) {
        return toAjax(pmsProductRequirementService.changeReqSpecs(productReqSpecsChangeVo));
    }

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

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

    /**
     * 需求规格纳入计划
     */
    @RequiresPermissions("pms:pmsProductRequirement:edit")
    @Log(title = "需求规格", businessType = BusinessType.UPDATE)
    @PutMapping("/activePlan")
    @ApiOperation(value = "需求规格纳入计划")
    public AjaxResult activePlan(@RequestBody @Validated ProductReqSpecsActivePlanVo productReqSpecsActivePlanVo) {
        return toAjax(pmsProductRequirementService.activePlan(productReqSpecsActivePlanVo));
    }

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

    /**
     * 查询需求规格类型列表
     */
    @ApiOperation(value = "查询需求规格类型列表")
    @RequiresPermissions("pms:pmsProduct:show")
    @GetMapping("/typeList")
    public List<EnumCommonVo> typeList() {
        return pmsProductRequirementService.selectReqSpecsTypeList();
    }
}
