package ink.wgink.module.activiti.controller.api.oa;

import ink.wgink.annotation.CheckRequestBodyAnnotation;
import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.module.activiti.pojo.dtos.oa.NodeFieldDTO;
import ink.wgink.module.activiti.pojo.vos.oa.UpdateEditableVO;
import ink.wgink.module.activiti.pojo.vos.oa.UpdateVisibleVO;
import ink.wgink.module.activiti.service.oa.INodeFieldService;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResult;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 表单字段与流程节点
 * @Author: WenG
 * @Date: 2022/3/17 19:49
 * @Version: 1.0
 **/
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "表单字段与流程节点")
@RestController
@RequestMapping(ISystemConstant.API_PREFIX + "/node-field")
public class NodeFieldController extends DefaultBaseController {

    @Autowired
    private INodeFieldService nodeFieldService;

    @ApiOperation(value = "更新显示状态", notes = "更新显示状态接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "nodeFieldId", value = "节点字段ID", paramType = "path")
    })
    @PutMapping("update-visible/{nodeFieldId}")
    @CheckRequestBodyAnnotation
    public SuccessResult updateVisible(@PathVariable("nodeFieldId") String nodeFieldId, @RequestBody UpdateVisibleVO updateVisibleVO) {
        nodeFieldService.updateVisible(nodeFieldId, updateVisibleVO.getIsVisible());
        return new SuccessResult();
    }

    @ApiOperation(value = "更新编辑状态", notes = "更新编辑状态接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "nodeFieldId", value = "节点字段ID", paramType = "path")
    })
    @PutMapping("update-editable/{nodeFieldId}")
    @CheckRequestBodyAnnotation
    public SuccessResult updateEditable(@PathVariable("nodeFieldId") String nodeFieldId, @RequestBody UpdateEditableVO updateEditableVO) {
        nodeFieldService.updateEditable(nodeFieldId, updateEditableVO.getIsEditable());
        return new SuccessResult();
    }

    @ApiOperation(value = "节点列表", notes = "节点列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deploymentId", value = "部署ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("list-node/deployment-id/{deploymentId}")
    public List<NodeFieldDTO> listNodeByDeploymentId(@PathVariable("deploymentId") String deploymentId) {
        return nodeFieldService.listNodeByDeploymentId(deploymentId);
    }

    @ApiOperation(value = "节点字段列表", notes = "节点字段列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deploymentId", value = "部署ID", paramType = "path"),
            @ApiImplicitParam(name = "flowNodeId", value = "节点ID", paramType = "path"),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("list/deployment-id/{deploymentId}/flow-node-id/{flowNodeId}")
    public List<NodeFieldDTO> listByDeploymentIdAndFlowNodeId(@PathVariable("deploymentId") String deploymentId, @PathVariable("flowNodeId") String flowNodeId) {
        return nodeFieldService.listByDeploymentIdAndNodeId(deploymentId, flowNodeId);
    }

}
