package com.atlassian.bitbucket.server;

import javax.annotation.Nonnull;

/**
 * Core {@link Feature features} provided by the application
 *
 * @since 4.2
 */
public enum StandardFeature implements Feature {

    ATTACHMENTS("attachments"),
    AUTH_CAPTCHA("auth.captcha"),
    FORKS("forks"),
    GETTING_STARTED("getting.started.page"),
    PERSONAL_REPOS("personal.repos"),
    PUBLIC_ACCESS("public.access"),
    SMART_MIRRORS("smart.mirrors", true),
    TIME_ZONE_ONBOARDING("user.time.zone.onboarding"),
    UPGRADE_ONBOARDING("upgrade.onboarding.page");

    private final boolean dataCenter;
    private final String key;

    StandardFeature(String key) {
        this(key, false);
    }

    StandardFeature(String key, boolean dataCenter) {
        this.dataCenter = dataCenter;
        this.key = key;
    }

    @Nonnull
    public static StandardFeature fromKey(String value) {
        for (StandardFeature feature : values()) {
            if (feature.getKey().equals(value)) {
                return feature;
            }
        }
        throw new IllegalArgumentException("No Feature is associated with key [" + value + "]");
    }

    @Nonnull
    @Override
    public String getKey() {
        return key;
    }

    @Override
    public boolean isDataCenter() {
        return dataCenter;
    }
}
