package com.njcn.gather.plan.pojo.enums;

import lombok.Getter;

import java.util.Objects;

/**
 * @author caozehui
 * @data 2024-12-12
 */
@Getter
public enum DataSourceEnum {
    REAL_DATA("real", "3s数据（150周波数据）"),

    MINUTE_STATISTICS_MAX("max", "分钟统计数据-最大值"),
    MINUTE_STATISTICS_MIN("min", "分钟统计数据-最小值"),
    MINUTE_STATISTICS_AVG("avg", "分钟统计数据-平均值"),
    MINUTE_STATISTICS_CP95("cp95", "分钟统计数据-CP95值"),
    WAVE_DATA("wave_data", "录波数据");

    private String value;
    private String msg;

    DataSourceEnum(String value, String msg) {
        this.value = value;
        this.msg = msg;
    }

    public static DataSourceEnum ofByValue(String value) {
        for (DataSourceEnum dataSourceEnum : DataSourceEnum.values()) {
            if (dataSourceEnum.getValue().equals(value)) {
                return dataSourceEnum;
            }
        }
        return null;
    }

    public static DataSourceEnum ofByMsg(String msg) {
        for (DataSourceEnum dataSourceEnum : DataSourceEnum.values()) {
            if (dataSourceEnum.getMsg().equals(msg)) {
                return dataSourceEnum;
            }
        }
        return null;
    }

    public static String getMsgByValue(String value) {
        return Objects.requireNonNull(ofByValue(value)).getMsg();
    }

    public static String getValueByMsg(String msg) {
        return Objects.requireNonNull(ofByMsg(msg)).getMsg();
    }
}
