package org.wcs.constant.enums.database;

import lombok.Getter;

import java.util.List;

@Getter
public enum StockSingleTaskStatusEnum {

    UNKNOWN(-1, "未知"),
    CREATE(0, "新建待执行"),
    QUEUE(1, "排队中"),
    EXECUTING(2, "执行中"),
    COMPLETE(3, "已完成"),
    CANCEL(4, "已取消"),
    ERROR(5, "任务异常"),
    TIMEOUT(6, "任务超时");

    private final Integer code;
    private final String msg;

    StockSingleTaskStatusEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static StockComposeTaskStatusEnum getByCode(int code) {
        for (StockComposeTaskStatusEnum stockComposeTaskStatusEnum : StockComposeTaskStatusEnum.values()) {
            if (stockComposeTaskStatusEnum.getCode().equals(code)) {
                return stockComposeTaskStatusEnum;
            }
        }
        return StockComposeTaskStatusEnum.UNKNOWN;
    }

    /**
     * 获取未完成状态码
     * @return 未完成状态码
     */
    public static List<Integer> notFinishedCodes() {
        return List.of(CREATE.getCode(), QUEUE.getCode(), EXECUTING.getCode(), TIMEOUT.getCode());
    }
}
