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.JFedException;
import be.iminds.ilabt.jfed.lowlevel.api_wrapper.UserAndSliceApiWrapper;
import be.iminds.ilabt.jfed.util.GeniUrn;
import be.iminds.ilabt.jfed.util.JavaFXLogger;

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

/**
 * User: twalcari
 * Date: 7/29/2015
 * Time: 11:02
 */
public class ListSubAuthorityMembersTask extends Task {

    private final String projectName;
    private final UserAndSliceApiWrapper userAndSliceApiWrapper;
    private final JavaFXLogger logger;

    private List<GeniUrn> memberUrns;

    public ListSubAuthorityMembersTask(String projectName, UserAndSliceApiWrapper userAndSliceApiWrapper, JavaFXLogger logger) {
        super("List members of " + projectName);
        this.projectName = projectName;
        this.userAndSliceApiWrapper = userAndSliceApiWrapper;
        this.logger = logger;
    }


    @Override
    protected void doTask(TaskExecution taskExecution) throws JFedException, InterruptedException {
        memberUrns =
                userAndSliceApiWrapper.getUsersForSubAuthority(JavaFXLogger.wrap(logger, taskExecution), projectName);
    }

    public List<GeniUrn> getMemberUrns() {
        return Collections.unmodifiableList(memberUrns);
    }
}
