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

    SAVE_TASK(10, "保存流程任务"),

    UPDATE_TASK_STATUS(20, "修改流程任务状态"),

    SET_READ_FLAG(30, "设置流程任务为已读状态"),

    DELETE_TASK(40, "删除流程任务");

    private final Integer code;

    private final String name;

    TaskEventTypeEnum(Integer value, String name) {
        this.code = value;
        this.name = name;
    }

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

    @Override
    public Object getName() {
        return name;
    }

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