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

    DRAFT(10, "草稿"),

    PROCESSING(20, "处理中"),

    FINISH(30, "已完成"),

    REJECT(40, "拒绝"),

    SUSPEND(50, "挂起"),

    INVALID(60, "作废");

    private final Integer status;

    private final String name;

    InstanceStatusEnum(Integer value, String name) {
        this.status = value;
        this.name = name;
    }

    public static String getInstanceStatusName(Integer value) {
        for (InstanceStatusEnum instanceStatusEnum : InstanceStatusEnum.values()) {
            if (instanceStatusEnum.getStatus().equals(value)) {
                return instanceStatusEnum.getName();
            }
        }
        return "";
    }

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

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