package org.nl.common.enums;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author 20220102CG\noblelift
 */
@Getter
@AllArgsConstructor
public enum TaskStatusEnum {
    /**
     * 任务状态
     */
    READY("0", "READY", "就绪"),
    BUSY("1", "BUSY", "执行中"),
    FINISHED("2", "FINISHED", "完成"),
    CANCEL("3", "CANCEL", "取消"),
    FORCED_COMPLETION("4", "", "强制完成"),
    ERROR("99", "ERROR", "异常");

    /**
     * 索引
     */
    private String index;
    /**
     * 编码
     */
    private String code;
    /**
     * 名字
     */
    private String name;
    /**
     * 描述
     */
    private String desc;

    /**
     * 构造方法
     * @param index
     * @param code
     * @param name
     */
    TaskStatusEnum(String index, String code, String name) {
        this.index = index;
        this.code = code;
        this.name = name;

    }

    public static JSONArray getList() {
        JSONArray arr = new JSONArray();
        JSONObject json = new JSONObject();
        for (TaskStatusEnum em : TaskStatusEnum.values()) {
            json.put("code", em.getCode());
            json.put("name", em.getName());
            arr.add(json);
        }
        return arr;
    }

    public static String getName(String index) {
        for (TaskStatusEnum c : TaskStatusEnum.values()) {
            if (c.index.equals(index)) {
                return c.name;
            }
        }
        return null;
    }

}
