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 ApplicationType {
    DAEMON_SET("DaemonSet", "apps.daemonsets", "确保每个节点（或指定节点）上都运行一个容器副本", "daemonsets"),
    DEPLOYMENT("Deployment", "apps.deployments", "管理无状态应用的容器副本，支持声明式更新和回滚", "deployments"),
    STATEFUL_SET("StatefulSet", "apps.statefulsets", "管理有状态应用，为容器提供稳定的标识和持久化存储", "statefulsets");
    private final String key;
    private final String fullName;
    private final String description;
    private final String name;

    ApplicationType(String key, String fullName, String description, String name) {
        this.key = key;
        this.fullName = fullName;
        this.description = description;
        this.name = name;
    }

    public static ApplicationType getApplicationTypeByKey(String key) {
        for (ApplicationType value : ApplicationType.values()) {
            if (StringUtils.equalsIgnoreCase(value.getKey(), key)) {
                return value;
            }
        }
        throw new ServiceException("该应用类型不存在(应用类型[%s])", key);
    }

    public static Boolean isApplicationType(String key) {
        for (ApplicationType value : ApplicationType.values()) {
            if (StringUtils.equalsIgnoreCase(value.getKey(), key)) {
                return true;
            }
        }
        return false;
    }
}
