package be.iminds.ilabt.jfed.preferences;

import be.iminds.ilabt.jfed.lowlevel.RetrySettings;
import com.google.common.collect.ImmutableMap;

import javax.annotation.Nonnull;
import java.io.File;
import java.util.Collections;
import java.util.List;

/**
 * User: twalcari
 * Date: 12/15/2015
 * Time: 17:05
 */
public class MockJFedPreferences implements JFedPreferences {

    private static final ImmutableMap<String, Object> config;
    private static final RetrySettings retrySettings = new RetrySettings();

    static {
        config = ImmutableMap.<String, Object>builder()
                .put(CorePreferenceKey.PREF_TESTBEDS_JSON_SOURCE.key, "AUTO")
                .put(CorePreferenceKey.PREF_DEBUG_CPU.key, false)
                .put(CorePreferenceKey.PREF_LOGGING_OVERWRITE.key, false)
                .put(CorePreferenceKey.PREF_LOGGING_ROOT_LEVEL.key, "INFO")
                .put(CorePreferenceKey.PREF_LOGGING_EXTTERM_LEVEL.key, "DEBUG")
                .put(CorePreferenceKey.PREF_TESTBEDSPECIFIC_EXOGENI_FORCE_EXOSM.key, "AUTO")
                .put(CorePreferenceKey.PREF_TESTBEDSPECIFIC_EXOGENI_RECOVER_METHOD.key, "BOTH")
                .build();


    }

    @Override
    public void fillinBlanks() {

    }

    @Override
    public boolean containsPreference(PreferenceKey key) {
        return config.containsKey(key.getKey());
    }

    @Override
    public boolean hasKey(PreferenceKey key) {
        return config.containsKey(key.getKey());
    }

    @Override
    public String getString(PreferenceKey key) {
        return (String) config.get(key.getKey());
    }

    @Nonnull
    @Override
    public List<String> getStringList(PreferenceKey key) {
        return (List<String>) config.get(key.getKey());
    }

    @Override
    public void setString(PreferenceKey key, String value) {
        throw new UnsupportedOperationException();
    }

    @Override
    public void setStringList(PreferenceKey key, @Nonnull List<String> value) {
        throw new UnsupportedOperationException();
    }

    @Override
    public Integer getInt(PreferenceKey key) {
        return (Integer) config.get(key.getKey());
    }

    @Override
    public void setInt(PreferenceKey key, Integer value) {

        throw new UnsupportedOperationException();
    }

    @Override
    public Boolean getBoolean(PreferenceKey key) {
        return (Boolean) config.get(key.getKey());
    }

    @Override
    public boolean getBoolean(PreferenceKey key, boolean defaultValue) {
        Boolean res = hasKey(key) ? getBoolean(key) : defaultValue;
        if (res == null) return defaultValue;
        return res;
    }

    @Override
    public void setBoolean(PreferenceKey key, Boolean value) {
        throw new UnsupportedOperationException();
    }

    @Override
    public File getFile(PreferenceKey key) {
        return (File) config.get(key.getKey());
    }

    @Override
    public void setFile(PreferenceKey key, File value) {
        throw new UnsupportedOperationException();
    }

    @Override
    public void clear(PreferenceKey key) {
        throw new UnsupportedOperationException();
    }

    @Override
    public File getPropertiesFile() {
        return null;
    }

    @Override
    public void addPreferenceChangeListener(PreferenceKey prefDebugCpu, PreferenceChangeListener preferenceChangeListener) {

    }

    @Override
    public void setRetrySettings(RetrySettings retrySettings) {
        throw new UnsupportedOperationException();
    }

    @Nonnull
    @Override
    public RetrySettings getRetrySettings() {
        return retrySettings;
    }
}
