package cn.axzo.workflow.common.model.request.bpmn;

import cn.axzo.workflow.common.enums.BpmnFlowNodeType;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * JSON 版本的 BPMN 协议模型
 * @author wangli
 */
@ApiModel("JSON 版本的 BPMN 协议模型")
@Data
@NoArgsConstructor
@Accessors(chain = true)
public class BpmnJsonNode implements Serializable {

    /**
     * 节点唯一标识
     */
    @ApiModelProperty(value = "节点ID")
    @NotBlank(message = "节点的 ID 不能为空")
    private String id;
    /**
     * 上级节点唯一标识
     */
    @ApiModelProperty(value = "父节点ID")
    private String parentId;
    /**
     * 节点类型 NODE_STARTER(发起人) NODE_TASK(审核节点) NODE_BUSINESS(业务节点) NODE_CARBON_COPY(抄送节点) NODE_EMPTY(空节点)
     * NODE_EXCLUSIVE_GATEWAY(排它网关) NODE_CONDITION(分支)
     */
    @ApiModelProperty(value = "节点类型")
    @NotNull(message = "节点类型不能为空")
    private BpmnFlowNodeType type;
    /**
     * 节点名称
     */
    @ApiModelProperty(value = "节点名称")
    private String name;
    /**
     * 子节点信息(一般子节点的类型为审批节点/业务节点/抄送节点; 条件分支用 branches 字段)
     */
    @ApiModelProperty(value = "子节点信息")
    private BpmnJsonNode children;
    /**
     * 分支节点信息(只用存储条件分支的信息, 而不能将审批节点/业务节点/抄送节点放到这里)
     */
    @ApiModelProperty(value = "分支节点信息")
    private List<BpmnJsonNode> branches;
    /**
     * 节点扩展属性, 比如审批方式/审批人指定等针对节点的配置信息
     */
    @ApiModelProperty(value = "节点扩展属性")
    private BpmnJsonNodeProperty property;


    /* 内部使用，不需要外界传 */
    private transient List<String> incoming = new ArrayList<>();
    /* 内部使用, 用于 JSON 格式转换 */
    private transient BpmnJsonNode preJsonNode;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public BpmnFlowNodeType getType() {
        return type;
    }

    public void setType(BpmnFlowNodeType type) {
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public BpmnJsonNode getChildren() {
        return children;
    }

    public void setChildren(BpmnJsonNode children) {
        this.children = children;
    }

    public List<BpmnJsonNode> getBranches() {
        return branches;
    }

    public void setBranches(List<BpmnJsonNode> branches) {
        this.branches = branches;
    }

    public BpmnJsonNodeProperty getProperty() {
        return property;
    }

    public void setProperty(BpmnJsonNodeProperty property) {
        this.property = property;
    }

    public List<String> getIncoming() {
        return incoming;
    }

    public void setIncoming(List<String> incoming) {
        this.incoming = incoming;
    }

    public BpmnJsonNode getPreJsonNode() {
        return preJsonNode;
    }

    public void setPreJsonNode(BpmnJsonNode preJsonNode) {
        this.preJsonNode = preJsonNode;
    }
}
