package com.haha.common.enums;

public enum DeviceOnlineStatus {

    OFFLINE(0, "离线"),
    ONLINE(1, "在线");

    private final int code;
    private final String description;

    DeviceOnlineStatus(int code, String description) {
        this.code = code;
        this.description = description;
    }

    public int getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    public static DeviceOnlineStatus fromCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (DeviceOnlineStatus status : values()) {
            if (status.code == code) {
                return status;
            }
        }
        return null;
    }

    public static boolean isOnline(Integer code) {
        return code != null && code == ONLINE.code;
    }
}
