package be.iminds.ilabt.jfed.experiment;

import be.iminds.ilabt.jfed.highlevel.model.InternalState;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.ReadOnlyObjectWrapper;

import javax.annotation.Nullable;
import java.time.Instant;

/**
 * An ExperimentPart is a collection of resources within an @link{Experiment} which are being managed by
 * one connection-authority.
 * <p/>
 * ex.
 * - all slivers managed by ExoGeni SM
 * - one GTS reservation of one GTS type
 */
public abstract class ExperimentPart {
    protected final Experiment experiment;

    protected final ReadOnlyObjectWrapper<InternalState> state = new ReadOnlyObjectWrapper<>();
    protected final ReadOnlyObjectWrapper<Instant> expirationTime = new ReadOnlyObjectWrapper<>();
    protected ExperimentPartsContainer container = null;

    public ExperimentPart(Experiment experiment) {
        this.experiment = experiment;
    }

    public Experiment getExperiment() {
        return experiment;
    }

    public abstract String getName();

    public InternalState getState() {
        return state.get();
    }

    public ReadOnlyObjectProperty<InternalState> stateProperty() {
        return state.getReadOnlyProperty();
    }

    public void setState(InternalState state) {
        this.state.set(state);
    }


    public ReadOnlyObjectProperty<Instant> expirationTimeProperty() {
        return expirationTime.getReadOnlyProperty();
    }

    @Nullable
    public Instant getExpirationTime() {
        return expirationTime.get();
    }

    public ExperimentPartsContainer getContainer() {
        return container;
    }

    public void setContainer(ExperimentPartsContainer container) {
        this.container = container;
    }
}
