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

import be.iminds.ilabt.jfed.highlevel.controller.Task;
import be.iminds.ilabt.jfed.highlevel.controller.TaskExecution;
import be.iminds.ilabt.jfed.lowlevel.GeniUserProvider;
import be.iminds.ilabt.jfed.lowlevel.JFedException;
import be.iminds.ilabt.jfed.lowlevel.api_wrapper.UserAndSliceApiWrapper;
import be.iminds.ilabt.jfed.util.JavaFXLogger;

import java.util.Collections;
import java.util.List;

/**
 * User: twalcari
 * Date: 6/16/2015
 * Time: 17:32
 */
public class UserSshKeysTask extends Task {

    private final UserAndSliceApiWrapper userAndSliceApiWrapper;
    private final JavaFXLogger logger;
    private final GeniUserProvider geniUserProvider;
    private final HighLevelTaskFactory highLevelTaskFactory;

    public UserSshKeysTask(UserAndSliceApiWrapper userAndSliceApiWrapper, JavaFXLogger logger, GeniUserProvider geniUserProvider, HighLevelTaskFactory highLevelTaskFactory) {
        super("Get User SSH Keys");
        this.userAndSliceApiWrapper = userAndSliceApiWrapper;
        this.logger = logger;
        this.geniUserProvider = geniUserProvider;
        this.highLevelTaskFactory = highLevelTaskFactory;
    }

    @Override
    public void doTask(TaskExecution taskExecution) throws JFedException, InterruptedException {
        userAndSliceApiWrapper.getSshKeysForUser(JavaFXLogger.wrap(logger, taskExecution),
                geniUserProvider.getLoggedInGeniUser().getUserUrn());

    }

    @Override
    public List<Task> initDependsOn() {
        return Collections.singletonList(highLevelTaskFactory.getUserCredential());
    }
}
