package com.zhyc.module.work.enums;


/**
 * 任务优先级枚举
 */
public enum TaskPriority {

    NORMAL(1, "普通"),
    IMPORTANT(2, "重要"),
    URGENT(3, "紧急");

    private final int code;
    private final String desc;

    TaskPriority(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public int getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    /**
     * 根据code获取描述
     */
    public static String getDescByCode(Integer code) {
        if (code == null) {
            return "";
        }
        for (TaskPriority priority : values()) {
            if (priority.code == code) {
                return priority.desc;
            }
        }
        return "";
    }

    /**
     * 根据code获取枚举
     */
    public static TaskPriority getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (TaskPriority priority : values()) {
            if (priority.code == code) {
                return priority;
            }
        }
        return null;
    }

    /**
     * 根据描述获取code
     */
    public static Integer getCodeByDesc(String desc) {
        if (desc == null || desc.trim().isEmpty()) {
            return null;
        }
        for (TaskPriority priority : values()) {
            if (priority.desc.equals(desc)) {
                return priority.code;
            }
        }
        return null;
    }
}