package de.zalando.aruha.nakadi.util;

import de.zalando.aruha.nakadi.repository.zookeeper.ZooKeeperHolder;
import org.apache.zookeeper.data.Stat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FeatureToggleService {

    private static final Logger LOG = LoggerFactory.getLogger(FeatureToggleService.class);

    private static final String PREFIX = "/nakadi/feature_toggle/";

    private final boolean forceEnableAll;
    private final ZooKeeperHolder zkHolder;

    public FeatureToggleService(final boolean forceEnableAll, final ZooKeeperHolder zkHolder) {
        this.forceEnableAll = forceEnableAll;
        this.zkHolder = zkHolder;
    }

    public boolean isFeatureEnabled(final Feature feature) {
        if (forceEnableAll) {
            return feature.getDefault();
        }
        try {
            final Stat stat = zkHolder.get().checkExists().forPath(PREFIX + feature.getId());
            return stat != null;
        } catch (Exception e) {
            LOG.warn("Error occurred when checking if feature '" + feature.getId() + "' is toggled", e);
            return false;
        }
    }

    public static class Feature {

        public static final Feature DISABLE_EVENT_TYPE_CREATION = new Feature("disable_event_type_creation", false);
        public static final Feature DISABLE_EVENT_TYPE_DELETION = new Feature("disable_event_type_deletion", false);
        public static final Feature HIGH_LEVEL_API = new Feature("high_level_api", true);

        private final String id;
        private final boolean defaultValue;

        private Feature(String id, boolean defaultValue) {
            this.id = id;
            this.defaultValue = defaultValue;
        }

        public String getId() {
            return id;
        }

        public boolean getDefault() {
            return defaultValue;
        }
    }
}

@@ -1144,20 +1144,12 @@
 lic 
-static class
+enum
  Fea
@@ -1168,36 +1168,8 @@
     
-public static final Feature 
 DISA
@@ -1187,38 +1187,24 @@
 YPE_CREATION
- = new Feature
 (%22disable_ev
@@ -1221,33 +1221,33 @@
 reation%22, false)
-;
+,
 %0A        public 
@@ -1243,36 +1243,8 @@
     
-public static final Feature 
 DISA
@@ -1266,30 +1266,16 @@
 DELETION
- = new Feature
 (%22disabl
@@ -1304,17 +1304,17 @@
 , false)
-;
+,
 %0A       
@@ -1318,64 +1318,22 @@
     
-public static final Feature HIGH_LEVEL_API = new Feature
+HIGH_LEVEL_API
 (%22hi
@@ -1352,16 +1352,26 @@
 %22, true)
+,%0A        
 ;%0A%0A     
@@ -1451,24 +1451,16 @@
         
-private 
 Feature(

change class to enum