package com.atlassian.stash.internal.web.fragments;

import com.atlassian.bitbucket.server.StandardFeature;
import com.atlassian.bitbucket.server.FeatureManager;
import com.atlassian.json.marshal.Jsonable;
import com.atlassian.json.marshal.wrapped.JsonableBoolean;
import com.atlassian.webresource.api.data.WebResourceDataProvider;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * @since 3.1
 */
public abstract class IsFeatureEnabledDataProvider implements WebResourceDataProvider {

    private final FeatureManager featureManager;

    private StandardFeature feature;

    protected IsFeatureEnabledDataProvider(FeatureManager featureManager, StandardFeature feature) {
        this.featureManager = featureManager;
        this.feature = checkNotNull(feature, "feature");
    }

    @Override
    public Jsonable get() {
        return new JsonableBoolean(featureManager.isEnabled(feature));
    }
}
