package be.iminds.ilabt.jfed;

import be.iminds.ilabt.jfed.fedmon.webapi.service.json.Testbed;
import be.iminds.ilabt.jfed.lowlevel.BasicTestbedInfoSource;
import be.iminds.ilabt.jfed.lowlevel.TestbedInfoSource;
import be.iminds.ilabt.jfed.lowlevel.authority.AuthorityFinder;
import be.iminds.ilabt.jfed.preferences.JFedPreferences;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;

import javax.inject.Singleton;
import java.util.List;

/**
 * User: twalcari
 * Date: 1/13/2015
 * Time: 11:40
 */
public class ManualTestbedInfoSourceModule extends AbstractModule {
    private final List<Testbed> testbeds;
    private final TestbedInfoSource testbedInfoSource;

    public ManualTestbedInfoSourceModule(List<Testbed> testbeds) {
        this.testbeds = testbeds;
        this.testbedInfoSource = BasicTestbedInfoSource.createFromTestbeds(testbeds);
        assert testbeds.size() <= testbedInfoSource.getTestbeds().size() : "Testbeds are being ignored: "+testbeds.size()+" > "+testbedInfoSource.getTestbeds().size();
        assert testbeds.size() <= testbedInfoSource.getServers().size() : "Servers are being ignored: "+testbeds.size()+" > "+testbedInfoSource.getServers().size();
    }

    @Override
    protected void configure() {
    }

    @Provides
    @Singleton
    private AuthorityFinder provideAuthorityFinder(TestbedInfoSource testbedInfoSource, JFedPreferences jFedPreferences) {
        return new AuthorityFinder(testbedInfoSource, jFedPreferences);
    }

    @Provides
    @Singleton
    private TestbedInfoSource provideTestbedInfoSource() {
        return testbedInfoSource;
    }
}
