package cn.stylefeng.workflow.api.enums;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.rule.base.ReadableEnum;
import lombok.Getter;

@Getter
public enum BackTypeEnum implements ReadableEnum<BackTypeEnum> {

    TO_START(1, "退回到开始节点"),

    TO_CUSTOM(2, "退回到指定节点");

    private final Integer code;

    private final String name;

    BackTypeEnum(Integer nodeType, String name) {
        this.code = nodeType;
        this.name = name;
    }

    @Override
    public Object getKey() {
        return code;
    }

    @Override
    public BackTypeEnum parseToEnum(String originValue) {
        if (ObjectUtil.isEmpty(originValue)) {
            return null;
        }
        for (BackTypeEnum value : BackTypeEnum.values()) {
            if (value.code.equals(Convert.toInt(originValue))) {
                return value;
            }
        }
        return null;
    }
}
