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 CycleTypeEnum implements ReadableEnum<CycleTypeEnum> {

    CYCLE_NUMBER(1, "指定次数"),

    CYCLE_WHILE_TRUE(2, "无限循环");

    private final Integer code;

    private final String name;

    CycleTypeEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

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

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

}
