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

import be.iminds.ilabt.jfed.highlevel.controller.TaskExecution;

import be.iminds.ilabt.jfed.highlevel.model.Slice;
import be.iminds.ilabt.jfed.lowlevel.GeniUserProvider;
import be.iminds.ilabt.jfed.lowlevel.JFedException;
import be.iminds.ilabt.jfed.lowlevel.TestbedInfoSource;
import be.iminds.ilabt.jfed.lowlevel.api.ReputationService;
import be.iminds.ilabt.jfed.lowlevel.connection.JFedConnectionProvider;
import be.iminds.ilabt.jfed.preferences.JFedPreferences;
import be.iminds.ilabt.jfed.util.GeniUrn;
import be.iminds.ilabt.jfed.util.JavaFXLogger;

import javax.annotation.Nonnull;
import java.util.Date;
import java.util.List;

/**
 * User: twalcari
 * Date: 1/8/2016
 * Time: 16:34
 */
public class RegisterReputationTask extends ReputationTask {

    @Nonnull
    private final Slice slice;
    @Nonnull
    private final List<GeniUrn> resources;
    private final int overallScore;
    private final int qualityScore;
    private final int availabilityScore;

    public RegisterReputationTask(@Nonnull Slice slice, @Nonnull List<GeniUrn> resources,
                                  int overallScore, int qualityScore, int availabilityScore,
                                  JavaFXLogger logger, JFedPreferences jFedPreferences,
                                  TestbedInfoSource testbedInfoSource,
                                  JFedConnectionProvider connectionProvider,
                                  GeniUserProvider geniUserProvider) {
        super("Registering reputation questionnaire to Reputation Service",
                logger, jFedPreferences, testbedInfoSource, connectionProvider, geniUserProvider);
        this.slice = slice;
        this.resources = resources;
        this.overallScore = overallScore;
        this.qualityScore = qualityScore;
        this.availabilityScore = availabilityScore;
    }

    @Override
    protected void doReputationTask(TaskExecution taskExecution, ReputationService reputationService)
            throws JFedException {

        reputationService.registerUserQOE(createConnection(),
                geniUserProvider.getLoggedInGeniUser().getUserUrn(),
                slice.getUrn(),
                slice.getCreationDate() != null ? Date.from(slice.getCreationDate()) : null,
                slice.getExpirationDate() != null ? Date.from(slice.getExpirationDate()) : null,
                resources, overallScore, qualityScore, availabilityScore);
    }
}
