package cn.axzo.workflow.core.engine.model;

import cn.axzo.workflow.common.enums.ApproverScopeEnum;
import cn.axzo.workflow.common.enums.ApproverSpecifyEnum;
import cn.axzo.workflow.common.enums.WorkspaceType;
import cn.axzo.workflow.common.exception.WorkflowEngineException;
import org.flowable.bpmn.model.FlowElement;

import static cn.axzo.workflow.common.code.FlowableEngineRespCode.ENGINE_NOTICE_CUSTOM_FLOW_ELEMENT_ERROR;

/**
 * 自定义扩展流程模型中的元素
 *
 * @author wangli
 * @since 2024/5/11 10:32
 */
public class NoticeFlowElement extends FlowElement {
    private Integer workspaceType;
    private ApproverSpecifyEnum specifyEnum;
    private String customValues;

    public NoticeFlowElement() {
    }

    public NoticeFlowElement(Integer workspaceType, ApproverSpecifyEnum specifyEnum, String customValues) {
        this.workspaceType = workspaceType;
        this.specifyEnum = specifyEnum;
        this.customValues = customValues;
    }

    public void setWorkspaceType(Integer workspaceType) {
        this.workspaceType = workspaceType;
    }

    public ApproverSpecifyEnum getSpecifyEnum() {
        return specifyEnum;
    }

    public void setSpecifyEnum(ApproverSpecifyEnum specifyEnum) {
        this.specifyEnum = specifyEnum;
    }

    public String getCustomValues() {
        return customValues;
    }

    public void setCustomValues(String customValues) {
        this.customValues = customValues;
    }

    public ApproverScopeEnum getProcessor() {
        switch (WorkspaceType.getType(workspaceType)) {
            case ENT:
            case OMS:
                return ApproverScopeEnum.entWorkspace;
            case GOVERNMENT:
                return ApproverScopeEnum.govWorkspace;
            case PROJECT:
                return ApproverScopeEnum.projectWorkspace;
            default:
                throw new WorkflowEngineException(ENGINE_NOTICE_CUSTOM_FLOW_ELEMENT_ERROR);
        }
    }

    @Override
    public NoticeFlowElement clone() {
        NoticeFlowElement clone = new NoticeFlowElement();
        clone.setValues(this);
        return clone;
    }
}
