package com.microservices.mon.k8s.domain;

import com.microservices.common.core.exception.ServiceException;
import com.microservices.common.core.utils.StringUtils;
import lombok.Getter;

/**
 * @author OTTO
 */
@Getter
public enum ApplicationEnvType {

    KEY_VALUE_PAIR("keyValuePair", "键值对"),
    RESOURCE("resource", "资源字段"),
    CONFIG_MAP_KEY("configMapKey", "ConfigMap键"),
    SECRET_KEY("secretKey", "Secret键"),
    POD_FIELD("podField", "容器字段"),
    SECRET("secret", "Secret整体"),
    CONFIGMAP("configMap", "ConfigMap整体");

    private final String key;
    private final String alias;

    ApplicationEnvType(String key, String alias) {
        this.key = key;
        this.alias = alias;
    }

    public static ApplicationEnvType getApplicationEnvTypeByKey(String type) {
        for (ApplicationEnvType applicationEnvType : ApplicationEnvType.values()) {
            if (StringUtils.equals(applicationEnvType.getKey(), type)) {
                return applicationEnvType;
            }
        }
        throw new ServiceException("该应用环境变量类型不存在(环境变量类型[%s])", type);
    }
}
