package com.zhyc.module.work.enums;


/**
 * 任务状态枚举
 */
public enum TaskStatus {

    PENDING(0, "待派工"),
    ASSIGNED(1, "已派工"),
    IN_PROGRESS(2, "执行中"),
    COMPLETED(3, "已完成"),
    CANCELLED(4, "已取消"),
    EXCEPTION(5, "异常");

    private final int code;
    private final String desc;

    TaskStatus(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 (TaskStatus status : values()) {
            if (status.code == code) {
                return status.desc;
            }
        }
        return "";
    }

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

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