package com.ruoyi.iot.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author wjh
 * 2024/7/11
 */
@Getter
@AllArgsConstructor
public enum IotHttpStatus {

    SUCCESS(0, "成功"),
    DEVICE_EXIST(10406, "设备已存在"),
    DEVICE_NON_EXISTENT(10410, "设备不存在"),
    DEVICE_ATTRIBUTE_SET_FAIL(10411, "设备属性设置失败"),
    DEVICE_ATTRIBUTE_DESIRE_SET_FAIL(10412, "设备属性期望设置失败"),
    DEVICE_ATTRIBUTE_DESIRE_QUERY_FAIL(10413, "设备属性期望查询失败"),
    DEVICE_ATTRIBUTE_DESIRE_GET_FAIL(10414, "设备属性获取失败"),
    DEVICE_SERVICE_CALL_FAIL(10415, "设备服务调用失败"),
    DEVICE_ATTRIBUTE_DESIRE_DELETE_FAIL(10416, "设备属性期望删除失败"),
    DEVICE_NEW_DATA_QUERY_FAIL(10417, "设备最新数据查询失败"),
    DEVICE_ATTRIBUTE_HISTORY_QUERY_FAIL(10418, "设备属性历史数据查询失败"),
    DEVICE_EVENT_HISTORY_DATA_QUERY_FAIL(10419, "设备事件历史数据查询失败"),
    DEVICE_OPERATE_RECORD_QUERY_FAIL(10420, "设备操作记录查询失败"),
    DEVICE_NOT_ONLINE(10421, "设备不在线"),
    TIME_OUT(10500, "发送命令超时"),
    UNKNOWN_ERROR(null, "未知错误");

    private final Integer code;
    private final String msg;

    public boolean equalCode(int code) {
        return this.code == code;
    }

    // 将code转换为枚举
    public static IotHttpStatus convertByCode(int code) {
        for (IotHttpStatus status : IotHttpStatus.values()) {
            if (status.getCode() != null && status.getCode() == code) {
                return status;
            }
        }
        return UNKNOWN_ERROR;
    }
}
