package be.iminds.ilabt.jfed.highlevel;

import be.iminds.ilabt.jfed.experiment.CapabilityChecker;
import be.iminds.ilabt.jfed.highlevel.jobs.parts.ExperimentPartControllerManager;
import be.iminds.ilabt.jfed.highlevel.tasks.HighLevelTaskFactory;
import be.iminds.ilabt.jfed.highlevel.tasks.SliceAuthorityTaskFactory;
import be.iminds.ilabt.jfed.highlevel.util.ProxySocketFactoryProvider;
import be.iminds.ilabt.jfed.highlevel.util.ProxySocketFactoryProviderImpl;
import be.iminds.ilabt.jfed.log.Logger;
import be.iminds.ilabt.jfed.log.cache.AllApiCallsList;
import be.iminds.ilabt.jfed.log.cache.ApiCallDetailsCache;
import be.iminds.ilabt.jfed.log.cache.DiskApiCallDetailsCache;
import be.iminds.ilabt.jfed.lowlevel.GeniUserProvider;
import be.iminds.ilabt.jfed.lowlevel.api_wrapper.UserAndSliceApiWrapper;
import be.iminds.ilabt.jfed.lowlevel.api_wrapper.impl.AutomaticUserAndSliceApiWrapper;
import be.iminds.ilabt.jfed.util.JavaFXLogger;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;

import javax.inject.Singleton;

/**
 * User: twalcari
 * Date: 11/27/2014
 * Time: 14:32
 */
public class HighLevelModule extends AbstractModule {
    @Provides
    @Singleton
    public UserAndSliceApiWrapper provideUserAndSliceApiWrapper(
            AutomaticUserAndSliceApiWrapper.AutomaticUserAndSliceApiWrapperFactory userAndSliceApiWrapperFactory,
            GeniUserProvider geniUserProvider) {
        //note: AutomaticUserAndSliceApiWrapper now supports user changes by checking geniUserProvider for each call

        return userAndSliceApiWrapperFactory.create();
    }


    @Override
    protected void configure() {
        bind(ApiCallDetailsCache.class).to(DiskApiCallDetailsCache.class).in(Singleton.class);
        bind(Logger.class).to(JavaFXLogger.class).in(Singleton.class);
        //must be eager because it is a listener for Logger
        bind(AllApiCallsList.class).asEagerSingleton();

        bind(SliceAuthorityTaskFactory.class).to(HighLevelTaskFactory.class);
        bind(CapabilityChecker.class).to(ExperimentPartControllerManager.class);
        bind(ProxySocketFactoryProvider.class).to(ProxySocketFactoryProviderImpl.class);
    }
}
