package com.njcn.csharmonic.enums;

import lombok.Getter;

@Getter
public enum CsTransientEnum {






    EVT_SYS_DIPSTR("Evt_Sys_DipStr","电压暂降"),
    EVT_SYS_INTRSTR("Evt_Sys_IntrStr","电压中断"),
    EVT_SYS_SWLSTR("Evt_Sys_SwlStr","电压暂升"),
    TRANSIENT("Transient","录波"),
    UN_KNOW("Un_Know","未知")


    ;

    private final String code;

    private final String name;

    CsTransientEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }



    /**
     * 根据code获取对应的name
     * @param code 枚举编码
     * @return 匹配的名称，未匹配时返回"未知"，code为null时返回"未知"
     */
    public static String getNameByCode(String code) {
        // 处理code为null的情况
        if (code == null) {
            return UN_KNOW.getName();
        }
        // 遍历所有枚举常量，匹配code
        for (CsTransientEnum transientEnum : CsTransientEnum.values()) {
            if (transientEnum.getCode().equals(code)) {
                return transientEnum.getName();
            }
        }
        // 未找到匹配的code时，返回未知名称
        return UN_KNOW.getName();
    }
}
