package be.iminds.jfed.gts_highlevel.tasks;

import be.iminds.ilabt.jfed.util.JavaFXLogger;
import be.iminds.jfed.gts_highlevel.controller.GtsModel;
import be.iminds.jfed.gts_highlevel.controller.GtsReservationManagerFactory;
import be.iminds.jfed.gts_highlevel.controller.LoginControllerFactory;
import be.iminds.jfed.gts_highlevel.model.GtsXmlProject;
import be.iminds.jfed.gts_highlevel.model.GtsXmlReservation;
import be.iminds.jfed.gts_highlevel.model.GtsXmlType;

import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import java.util.List;

/**
 * User: twalcari
 * Date: 10/8/2015
 * Time: 15:45
 */
@Singleton
public class GtsTaskFactory {
    private final LoginControllerFactory loginControllerFactory;
    private final GtsReservationManagerFactory gtsReservationManagerFactory;
    private final Provider<GtsLoginTask> loginGtsTaskProvider;
    private final GtsModel gtsModel;
    private final JavaFXLogger logger;

    @Inject
    public GtsTaskFactory(LoginControllerFactory loginControllerFactory, GtsReservationManagerFactory gtsReservationManagerFactory,
                          Provider<GtsLoginTask> loginGtsTaskProvider, GtsModel gtsModel, JavaFXLogger logger) {
        this.loginControllerFactory = loginControllerFactory;
        this.gtsReservationManagerFactory = gtsReservationManagerFactory;
        this.loginGtsTaskProvider = loginGtsTaskProvider;
        this.gtsModel = gtsModel;
        this.logger = logger;
    }

    public CreateGtsProjectTask createCreateGtsProjectTask(String projectName, String vpnUsername, String vpnPassword, List<String> users) {
        return new CreateGtsProjectTask(projectName, vpnUsername, vpnPassword, users,
                gtsReservationManagerFactory, loginGtsTaskProvider, gtsModel, logger);
    }

    public DeleteGtsProjectTask createDeleteGtsProjectTask(GtsXmlProject project) {
        return new DeleteGtsProjectTask(project, gtsReservationManagerFactory, loginGtsTaskProvider, gtsModel, logger);
    }

    public StartGtsResourcesTask createStartGtsResourcesTask(String scriptName, String script, GtsXmlProject project) {
        return new StartGtsResourcesTask(scriptName, script, project,
                gtsReservationManagerFactory, loginGtsTaskProvider, gtsModel, logger);
    }

    public StopGtsResourcesTask createStopGtsResourcesTask(@Nonnull GtsXmlReservation reservation, @Nonnull GtsXmlType type, @Nonnull GtsXmlProject project) {
        return new StopGtsResourcesTask(reservation, type, project,
                gtsReservationManagerFactory, loginGtsTaskProvider, gtsModel, logger);
    }

    public UpdateGtsReservationTask createUpdateGtsReservationTask(GtsXmlProject project, int reservationId){
        return new UpdateGtsReservationTask(project, reservationId,
                gtsReservationManagerFactory, loginGtsTaskProvider, gtsModel, logger);
    }

    public GtsLoginTask createLoginGtsTask(){
        return new GtsLoginTask(loginControllerFactory, gtsModel, logger);
    }

    public GtsListResourcesTask createGtsListResourcesTask() {
        return new GtsListResourcesTask(logger, gtsReservationManagerFactory, loginGtsTaskProvider, gtsModel);
    }

    public GtsListResourcesTask createGtsListResourcesTask(@Nonnull GtsXmlProject project) {
        return new GtsListResourcesTask(project, logger, gtsReservationManagerFactory, loginGtsTaskProvider, gtsModel);
    }
}
