package com.friday.tooldriver.constants.infodator;

import java.util.Arrays;

/**
 * 容智OCtask执行状态说明
 */
public enum InfodatorTaskRunStatusEnum {

    Invalid(-1,"无效状态"),
    Initializing(0,"未分配，刚刚初始化完，尚未进入等待(未发起执行)"),
    Waiting(1,"等待运行。对于任务，因为对应多个Queue，按照最活跃的状态来显示任务的状态，级别相同时，按照最近发生的状态改变来显示"),
    Running(2,"正在运行"),
    Pausing(3,"正在暂停(等当前条目完成)"),
    Paused(4,"已暂停"),
    Cancelling(5,"正在取消(等当前条目完成)"),
    Cancelled(6,"已取消"),
    Idle(7,"空闲"),
    Timeout(97,"任务超时"),
    CompletedWithError(98,"完成且有错"),
    Completed(99,"完成"),
    Terminated(100,"异常终止"),
    ;

    private Integer code;
    private String meaning;

    InfodatorTaskRunStatusEnum(Integer code, String meaning) {
        this.code = code;
        this.meaning = meaning;
    }

    public Integer getCode() {
        return code;
    }

    public String getMeaning() {
        return meaning;
    }

    public static String getMeaningByCode(Integer code){
        return Arrays.stream(values()).filter(taskRunStatus -> taskRunStatus.getCode().equals(code)).map(InfodatorTaskRunStatusEnum::getMeaning).findFirst().orElse("");
    }

    public static InfodatorTaskRunStatusEnum getCode(Integer code){
        return Arrays.stream(values()).filter(statusEnum -> statusEnum.getCode().equals(code)).findFirst().orElse(Invalid);
    }

    public static void main(String[] args) {
        System.out.println(InfodatorTaskRunStatusEnum.getMeaningByCode(1));
    }
}
