package be.iminds.ilabt.jfed.highlevel.jobs;

import be.iminds.ilabt.jfed.experiment.SfaExperimentPart;
import be.iminds.ilabt.jfed.highlevel.jobs.parts.ExperimentPartControllerManager;
import be.iminds.ilabt.jfed.highlevel.jobs.sfa_parts.SfaExperimentPartController;
import be.iminds.ilabt.jfed.highlevel.stitcher.TestStitchingXmlRpcHelper;
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.ApiCallDetailsCache;
import be.iminds.ilabt.jfed.log.cache.MemoryApiCallDetailsCache;
import be.iminds.ilabt.jfed.lowlevel.TestCertHelper;
import be.iminds.ilabt.jfed.lowlevel.api_wrapper.UserAndSliceApiWrapper;
import be.iminds.ilabt.jfed.lowlevel.api_wrapper.impl.AutomaticUserAndSliceApiWrapper;
import be.iminds.ilabt.jfed.preferences.JFedPreferences;
import be.iminds.ilabt.jfed.preferences.MockJFedPreferences;
import be.iminds.ilabt.jfed.util.JavaFXLogger;
import com.google.inject.Binder;
import com.google.inject.Module;
import com.google.inject.Provides;

import javax.inject.Provider;
import javax.inject.Singleton;

/**
 * User: twalcari
 * Date: 12/9/2015
 * Time: 11:40
 */
public class StitchingTestModule implements Module {
    @Provides
    @Singleton
    public UserAndSliceApiWrapper provideUserAndSliceApiWrapper(
            AutomaticUserAndSliceApiWrapper.AutomaticUserAndSliceApiWrapperFactory userAndSliceApiWrapperFactory) {
        return userAndSliceApiWrapperFactory.create();
    }

    @Provides
    public TestStitchingXmlRpcHelper provideTestStitchingXmlRpcHelper(TestCertHelper testCertHelper){
        return new TestStitchingXmlRpcHelper(testCertHelper);
    }


    @Provides
    @Singleton
    public ExperimentPartControllerManager getEpcManager(Provider<SfaExperimentPartController> sfaExperimentPartControllerProvider){
        ExperimentPartControllerManager epcManager = new ExperimentPartControllerManager(true);
        epcManager.registerController(SfaExperimentPart.class, sfaExperimentPartControllerProvider.get());

        return epcManager;
    }


    @Override
    public void configure(Binder binder) {
        binder.bind(JFedPreferences.class).to(MockJFedPreferences.class).in(Singleton.class);
        binder.bind(ApiCallDetailsCache.class).to(MemoryApiCallDetailsCache.class).in(Singleton.class);
        binder.bind(Logger.class).to(JavaFXLogger.class).in(Singleton.class);
        binder.bind(SliceAuthorityTaskFactory.class).to(HighLevelTaskFactory.class);
        binder.bind(ProxySocketFactoryProvider.class).to(ProxySocketFactoryProviderImpl.class);
    }
}
