package org.wcs.constant.enums.etag;

import lombok.Getter;

/**
 * 标签闪烁频率
 */
@Getter
public enum LedBlinkingEnum {

    LED_OFF(0, "关闭"),
    LED_ON(1, "打开，常亮"),
    BLINKING_2(2, "2秒闪烁一次"),
    BLINKING_1(3, "1秒闪烁一次"),
    BLINKING_0_5(4, "0.5秒闪烁一次"),
    BLINKING_0_25(5, "0.25秒闪烁一次");

    private final Integer code;
    private final String desc;

    LedBlinkingEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static LedBlinkingEnum getByCode(Integer code) {
        for (LedBlinkingEnum value : LedBlinkingEnum.values()) {
            if (value.code.equals(code)) {
                return value;
            }
        }
        return null;
    }

    /**
     * 获取闪烁频率对应的二进制字符串
     * @param ledBlinking 闪烁频率
     * @return 二进制字符串
     */
    public static String getBlinkingBitString(LedBlinkingEnum ledBlinking) {
        return switch (ledBlinking) {
            case LED_OFF -> "000";
            case LED_ON -> "001";
            case BLINKING_2 -> "010";
            case BLINKING_1 -> "011";
            case BLINKING_0_5 -> "100";
            case BLINKING_0_25 -> "101";
        };
    }
}
