package com.qmth.teachcloud.common.enums;

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

/**
 * @Description: 任务状态enum
 * @Param:
 * @return:
 * @Author: wangliang
 * @Date: 2021/3/29
 */
public enum TaskStatusEnum {

    INIT("未开始"),

    DATA_VALID("数据校验中"),

    RUNNING("进行中"),

    FINISH("已完成");

    private String title;

    private TaskStatusEnum(String title) {
        this.title = title;
    }

    public String getTitle() {
        return title;
    }

    /**
     * 状态转换 toName
     *
     * @param title
     * @return
     */
    public static String convertToName(String title) {
        for (TaskStatusEnum e : TaskStatusEnum.values()) {
            if (Objects.equals(title, e.getTitle())) {
                return e.name();
            }
        }
        return null;
    }

    public static List<EnumResult> listTypes() {
        List<EnumResult> list = new ArrayList<>();
        for (TaskStatusEnum value : TaskStatusEnum.values()) {
            EnumResult result = new EnumResult();
            result.setName(value.name());
            result.setOrdinal(value.ordinal());
            result.setCode(null);
            result.setDesc(value.getTitle());
            list.add(result);
        }
        return list;
    }
}
