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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nonnull;
import javax.inject.Provider;

/**
 * User: twalcari
 * Date: 9/25/2015
 * Time: 15:46
 */

public class DeleteGtsProjectTask extends LoggedInGtsTask {
    private static final Logger LOG = LoggerFactory.getLogger(DeleteGtsProjectTask.class);

    private final GtsXmlProject project;

    DeleteGtsProjectTask(@Nonnull GtsXmlProject project,
                         GtsReservationManagerFactory gtsReservationManagerFactory,
                         Provider<GtsLoginTask> loginGtsTaskProvider,
                         GtsModel gtsModel, JavaFXLogger logger) {
        super("Delete GTS project " + project.getId(), logger, gtsReservationManagerFactory, loginGtsTaskProvider, gtsModel);
        this.project = project;
    }

    @Override
    protected void doGtsRMTask(TaskExecution taskExecution, GtsReservationManager reservationManager) throws GtsException {
        LOG.debug("Deleting project " + project.getId());

        reservationManager.removeProject(project.getId());
    }

    public GtsXmlProject getProject() {
        return project;
    }
}
