package com.muyu.common.caffeine.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.List;

/**
 * 缓存分区枚举
 *
 * @Author: WangXin
 * @Name: CacheNameEnums
 * @Description: 缓存分区枚举
 */

@Getter
public enum CacheNameEnums {
    STORAGE("storage", "持久化"),
    FAULT("fault", "故障"),
    FENCE("fence", "围栏"),
    WARMING("warming", "预警"),
    REALTIME("realTime", "实时信息");

    private final String code;
    private final String info;

    CacheNameEnums(String code, String info) {
        this.code = code;
        this.info = info;
    }

    /**
     * 鉴别参数是否是枚举的值
     *
     * @param code 需鉴别参数
     * @return 如果存在返回结果turn, 否则返回false
     */
    public static boolean isCode(String code) {
        return Arrays.stream(values())
                .map(CacheNameEnums::getCode)
                .anyMatch(c -> c.equals(code));
    }

    /**
     * 获取枚举Value
     * @param code 编码
     * @return  Value
     */
    public static String getInfo(String code) {
        return Arrays.stream(values())
                .filter(c -> c.getCode().equals(code))
                .map(CacheNameEnums::getInfo)
                .findFirst()
                .orElse("");
    }

    /**
     * 获取所有code
     * @return code集合
     */
    public static List<String> getCodes() {
        return Arrays.stream(values())
                .map(CacheNameEnums::getCode)
                .toList();
    }
}
