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

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

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

/**
 * @since 4.7
 */
public abstract class IsDarkFeatureEnabledDataProvider implements WebResourceDataProvider {

    private final FeatureManager featureManager;

    private DarkFeature feature;

    protected IsDarkFeatureEnabledDataProvider(FeatureManager featureManager, DarkFeature feature) {
        this.featureManager = featureManager;
        this.feature = checkNotNull(feature, "feature");
    }

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