package be.iminds.jfed.gts_highlevel.tasks;

import be.iminds.ilabt.jfed.highlevel.controller.TaskExecution;
import be.iminds.ilabt.jfed.util.JavaFXLogger;
import be.iminds.jfed.gts_highlevel.controller.GtsException;
import be.iminds.jfed.gts_highlevel.controller.GtsModel;
import be.iminds.jfed.gts_highlevel.controller.GtsReservationManager;
import be.iminds.jfed.gts_highlevel.controller.GtsReservationManagerFactory;
import be.iminds.jfed.gts_highlevel.model.GtsXmlProject;

import javax.annotation.Nullable;
import javax.inject.Provider;

/**
 * User: twalcari
 * Date: 10/9/2015
 * Time: 10:03
 */
public class GtsListResourcesTask extends LoggedInGtsTask {

    @Nullable
    private final GtsXmlProject project;

    public GtsListResourcesTask(GtsXmlProject project, JavaFXLogger logger, GtsReservationManagerFactory gtsReservationManagerFactory, Provider<GtsLoginTask> loginGtsTaskProvider, GtsModel gtsModel) {
        super("GTS List Resources", logger, gtsReservationManagerFactory, loginGtsTaskProvider, gtsModel);
        this.project = project;
    }

    public GtsListResourcesTask(JavaFXLogger logger, GtsReservationManagerFactory gtsReservationManagerFactory, Provider<GtsLoginTask> loginGtsTaskProvider, GtsModel gtsModel) {
        this(null, logger, gtsReservationManagerFactory, loginGtsTaskProvider, gtsModel);
    }


    @Override
    protected void doGtsRMTask(TaskExecution taskExecution, GtsReservationManager reservationManager) throws GtsException {
        if (project != null)
            reservationManager.listResources(project);
        else
            reservationManager.listResources();
    }

    @Nullable
    public GtsXmlProject getProject() {
        return project;
    }
}
