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

import be.iminds.ilabt.jfed.lowlevel.stitching.StitchingCallData;
import be.iminds.ilabt.jfed.lowlevel.stitching.VlanRange;
import be.iminds.ilabt.jfed.lowlevel.stitching.info.Hop;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;

import java.util.ArrayList;
import java.util.List;

/**
 * HopInfo is the mutable javaFX version of the POJO immutable Hop class
 *
 * So this is purely informational hop data
 *
 * Some data will never change after this object has been created, there are no javaFX properties available for this data.
 */
public class HopInfo {
    private final String linkName;
    private final String authUrn;
    private final String hopUrn;
    private final boolean importsVlans;

    /** initialised after constructor, and doesn;t change after that. */
    final List<HopInfo> dependsOn = new ArrayList<>();
    /** initialised after constructor, and doesn;t change after that. */
    final List<HopInfo> dependingOnThis = new ArrayList<>();

    private final ObjectProperty<StitchingCallData.State> authState = new SimpleObjectProperty<>();
    private final ObjectProperty<VlanRange> availableVlans = new SimpleObjectProperty<>();
    private final ObjectProperty<VlanRange> unavailableVlans = new SimpleObjectProperty<>();
    private final IntegerProperty suggestedVlan = new SimpleIntegerProperty(); //if negative, there is no suggested VLAN
    private final IntegerProperty confirmedVlan = new SimpleIntegerProperty(); //if negative, there is no confirmed VLAN

    public HopInfo(Hop hop) {
        this.linkName = hop.getLinkName();
        this.authUrn = hop.getAuthUrn();
        this.hopUrn = hop.getHopUrn();
        this.importsVlans = hop.isImportsVlans();

        update(hop);
    }

    public void update(Hop hop) {
        authState.set(hop.getAuthState());
        availableVlans.set(hop.getAvailableVlans());
        unavailableVlans.set(hop.getUnavailableVlans());
        suggestedVlan.set(hop.getSuggestedVlan() == null ? -1 : hop.getSuggestedVlan());
        confirmedVlan.set(hop.getConfirmedVlan() == null ? -1 : hop.getConfirmedVlan());
    }

    public String getLinkName() {
        return linkName;
    }

    public String getAuthUrn() {
        return authUrn;
    }

    public String getHopUrn() {
        return hopUrn;
    }

    public boolean isImportsVlans() {
        return importsVlans;
    }

    public List<HopInfo> getDependsOn() {
        return dependsOn;
    }

    public List<HopInfo> getDependingOnThis() {
        return dependingOnThis;
    }

    public StitchingCallData.State getAuthState() {
        return authState.get();
    }

    public ObjectProperty<StitchingCallData.State> authStateProperty() {
        return authState;
    }

    public VlanRange getAvailableVlans() {
        return availableVlans.get();
    }

    public ObjectProperty<VlanRange> availableVlansProperty() {
        return availableVlans;
    }

    public VlanRange getUnavailableVlans() {
        return unavailableVlans.get();
    }

    public ObjectProperty<VlanRange> unavailableVlansProperty() {
        return unavailableVlans;
    }

    public int getSuggestedVlan() {
        return suggestedVlan.get();
    }

    public IntegerProperty suggestedVlanProperty() {
        return suggestedVlan;
    }

    public int getConfirmedVlan() {
        return confirmedVlan.get();
    }

    public IntegerProperty confirmedVlanProperty() {
        return confirmedVlan;
    }
}
