package org.dromara.zhishu.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.dromara.common.core.exception.ServiceException;

import java.util.ArrayList;
import java.util.List;

/**
 * 计划任务执行状态类型枚举
 */
@Getter
@AllArgsConstructor
public enum TaskStatusTypeEnum {

    NOT_EXECUTE("0", "未执行"),

    EXECUTING("1", "执行中"),

    EXECUTE_PAUSE_STOP("2", "暂停/停止"),

    EXECUTED("3", "已完成");

    /**
     * code
     */
    private final String code;

    /**
     * message
     */
    private final String msg;

    public static List<String> getTaskStatusTypeEnumList() {
        List<String> taskStatusTypeEnumList = new ArrayList<>();
        for (TaskStatusTypeEnum item : values()) {
            taskStatusTypeEnumList.add(item.getCode());
        }
        return taskStatusTypeEnumList;
    }

    public static TaskStatusTypeEnum valueOfCode(String code) {
        for (TaskStatusTypeEnum type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        throw new ServiceException("未知操作库存类型code: " + code);
    }

}
