package cn.iocoder.yudao.framework.common.enums;

import cn.hutool.core.util.ObjUtil;
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 设备连接状态枚举
 *
 * @author 芋道源码
 */
@Getter
@AllArgsConstructor
public enum DeviceConnectionStatusEnum implements IntArrayValuable {

    CONNECTED(1, "已连接"),
    DISCONNECTED(2, "已断开");

    public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(DeviceConnectionStatusEnum::getStatus).toArray();

    /**
     * 状态值
     */
    private final Integer status;
    
    /**
     * 状态名
     */
    private final String name;

    @Override
    public int[] array() {
        return ARRAYS;
    }

    /**
     * 判断是否为连接状态
     */
    public static boolean isConnected(Integer status) {
        return ObjUtil.equal(CONNECTED.status, status);
    }

    /**
     * 判断是否为断开状态
     */
    public static boolean isDisconnected(Integer status) {
        return ObjUtil.equal(DISCONNECTED.status, status);
    }

    /**
     * 根据状态值获取枚举实例
     */
    public static DeviceConnectionStatusEnum valueOf(Integer status) {
        if (status == null) {
            return null;
        }
        for (DeviceConnectionStatusEnum value : values()) {
            if (ObjUtil.equal(value.status, status)) {
                return value;
            }
        }
        return null;
    }
}