package cz.moneta.test.harness.config;

import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.Endpoint;
import cz.moneta.test.harness.support.data.GeneratorType;
import cz.moneta.test.harness.support.util.Level;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;

public class MockConfig implements StoreAccessor {

    private final Map<String, String> config;

    private MockConfig(Map<String, String> config) {
        this.config = config;
    }

    public static MockConfigBuilder builder() {
        return new MockConfigBuilder();
    }

    @Override
    public <E extends Endpoint> E getEndpoint(Class<E> endpointClass, Object... args) {
        return null;
    }

    @Override
    public void closeEndpoint(Endpoint endpoint) {}

    @Override
    public <E extends Endpoint> Set<E> getActiveEndpoints() {
        return null;
    }

    @Override
    public String getConfig(String key) {
        return config.get(key);
    }

    @Override
    public String getConfig(String key, String defaultValue) {
        return config.getOrDefault(key, defaultValue);
    }

    @Override
    public void putConfig(String key, String value) {}

    @Override
    public <T> T get(String key) {
        return null;
    }

    @Override
    public <T> T get(String key, boolean nullEnabled) {
        return null;
    }

    @Override
    public void store(String key, Object value) {}

    @Override
    public <T> T getGlobal(String key, Supplier<T> orCreate) {
        return null;
    }

    @Override
    public <T> T getGlobal(String key) {
        return null;
    }

    @Override
    public void storeGlobal(String key, Object value) {}

    @Override
    public void storeGlobal(String key, Supplier orCreate) {}

    @Override
    public void log(String template, Object... args) {}

    @Override
    public void log(Level level, String template, Object... args) {}

    @Override
    public <T> T generate(GeneratorType type, Object... param) {
        return null;
    }

    public static final class MockConfigBuilder {

        private final Map<String, String> config = new ConcurrentHashMap<>();

        private MockConfigBuilder() {}

        public MockConfigBuilder put(String key, String value) {
            config.put(key, value);
            return this;
        }

        public MockConfig build() {
            return new MockConfig(config);
        }
    }

}
