package cn.iocoder.yudao.module.iot.controller.admin.device.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 设备运行报警状态枚举
 */
@Getter
@AllArgsConstructor
public enum DeviceBasicStatusEnum {
    /**
     * 运行状态
     */
    RUNNING("1", "运行", "RUNNING"),

    /**
     * 报警状态
     */
    ALARM("2", "报警", "ALARM");

    /**
     * 状态编码
     */
    private final String code;

    /**
     * 状态名称
     */
    private final String name;

    /**
     * 状态描述
     */
    private final String description;

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

    /**
     * 根据描述获取枚举
     */
    public static DeviceBasicStatusEnum getByDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            return null;
        }
        for (DeviceBasicStatusEnum status : values()) {
            if (status.getDescription().equalsIgnoreCase(description.trim())) {
                return status;
            }
        }
        return null;
    }

    /**
     * 检查编码是否有效
     */
    public static boolean isValidCode(Integer code) {
        return getByCode(code) != null;
    }

    @Override
    public String toString() {
        return this.name;
    }
}