package com.fjhx.enums;

import com.fjhx.utils.Assert;
import lombok.Getter;

import java.util.HashMap;

/**
 * 质检状态
 */
@Getter
public enum WebSocketOnMessageTypeEnum {

    HANDHELD_MACHINE_RFID_SCANNING(1, "一体机rfid扫描"),
    HANDHELD_MACHINE_RFID_CLOSE_SCANNING(2, "一体机关闭rfid扫描")

    ;

    private final Integer type;
    private final String name;

    private static final HashMap<Integer, WebSocketOnMessageTypeEnum> map = new HashMap<>();

    WebSocketOnMessageTypeEnum(Integer type, String name) {
        this.type = type;
        this.name = name;
    }

    static {
        for (WebSocketOnMessageTypeEnum value : WebSocketOnMessageTypeEnum.values()) {
            map.put(value.getType(), value);
        }
    }

    /**
     * 根据type获取枚举
     */
    public static WebSocketOnMessageTypeEnum get(Integer type) {
        WebSocketOnMessageTypeEnum webSocketOnMessageTypeEnum = map.get(type);
        Assert.notEmpty(webSocketOnMessageTypeEnum, "未知type类型");
        return webSocketOnMessageTypeEnum;
    }

    /**
     * 根据type值获取枚举
     */
    public static String getName(Integer type) {
        return map.get(type).getName();
    }


}
