package be.iminds.ilabt.jfed;

import be.iminds.ilabt.jfed.preferences.CorePreferenceKey;
import be.iminds.ilabt.jfed.preferences.JFedCorePreferences;
import be.iminds.ilabt.jfed.preferences.JFedPreferences;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;

/**
 * CorePreferencesModule
 */
public class CorePreferencesModule extends AbstractModule {
    private JFedCorePreferences jFedCorePreferences;
    private final String testbedsFileName;

    public CorePreferencesModule() {
        this.testbedsFileName = null;
    }
    public CorePreferencesModule(String testbedsFileName) {
        this.testbedsFileName = testbedsFileName;
    }

    @Override
    protected void configure() {
//        bind(JFedPreferences.class).to(JFedCorePreferences.class).in(Singleton.class);
    }

    @Provides
    @javax.inject.Singleton
    public JFedPreferences provideJFedPreferences() {
        if (jFedCorePreferences == null) {
            jFedCorePreferences = new JFedCorePreferences();
            if (testbedsFileName != null) {
                jFedCorePreferences.setString(CorePreferenceKey.PREF_TESTBEDS_JSON_SOURCE, testbedsFileName);
            }
        }
        return jFedCorePreferences;
    }
}
