package be.iminds.ilabt.jfed;

import com.google.inject.AbstractModule;
import javax.inject.Singleton;

import java.util.Collections;
import java.util.Map;

public class ApplicationParametersModule extends AbstractModule {
    @Singleton
    public static class ApplicationParameters {
        private Map<String, String> parameters;

        public ApplicationParameters() {
            this.parameters = Collections.emptyMap();
        }
        public ApplicationParameters(Map<String, String> parameters) {
            this.parameters = parameters;
        }

        public Map<String, String> getParameters() {
            return parameters;
        }

        /**
         * Note: if you have to use this, it will probably not be used durng init. Use the constructor for that.
         * It is only ok to use it for parameters that can change after everything has been inited and started.
         */
        public void setParameters(Map<String, String> parameters) {
            this.parameters = parameters;
        }
    }

    public ApplicationParametersModule(Map<String, String> applicationParameters) {
        this.applicationParameters = new ApplicationParameters(applicationParameters);
    }

    private final ApplicationParameters applicationParameters;

    @Override
    protected void configure() {
        bind(ApplicationParameters.class).toInstance(applicationParameters);
    }
}
