package ui.model;

import java.util.ArrayList;
import java.util.HashMap;

import classes.AbstractCpsObject;
import classes.CpsEdge;
import classes.CpsNode;
import classes.CpsUpperNode;
import classes.HolonObject;
import classes.HolonSwitch;
import ui.model.DecoratedCable.CableState;

/**
 * For DecoratedState And VisualRepresentationalState
 * @author Tom
 *
 */
public class MinimumModel {
	
	private ArrayList<HolonObject> holonObjectList = new ArrayList<HolonObject>();
	private ArrayList<IntermediateCableWithState> cableList = new ArrayList<IntermediateCableWithState>();
	private ArrayList<CpsNode> nodeList = new ArrayList<CpsNode>();
	private ArrayList<HolonSwitch> switchList = new ArrayList<HolonSwitch>();
	
	//-->Only for Visual:
	private ArrayList<CpsUpperNode> uppderNodeList = new ArrayList<CpsUpperNode>();
	private HashMap<AbstractCpsObject, CpsUpperNode> inGroupObjects = new HashMap<>();
	private HashMap<CpsEdge, CpsUpperNode> inGroupEdges = new HashMap<>();
	//<--
	
	public MinimumModel(ArrayList<AbstractCpsObject> abstractObjectList, ArrayList<CpsEdge> edgeList) {// Constructor because of old Model
		for (AbstractCpsObject aCps : abstractObjectList) {
			if (aCps instanceof HolonObject) holonObjectList.add((HolonObject) aCps);
			else if (aCps instanceof CpsNode) nodeList.add((CpsNode) aCps);
			else if (aCps instanceof HolonSwitch) switchList.add((HolonSwitch) aCps);
			else if(aCps instanceof CpsUpperNode) {
				addUpperObjects((CpsUpperNode)aCps);
				uppderNodeList.add((CpsUpperNode)aCps);
			}
		}
		for (CpsEdge edge : edgeList) {
			this.cableList.add(new IntermediateCableWithState(edge, CableState.Working));
		}
	}

	private void addUpperObjects(CpsUpperNode aUpperNode) {
		for(AbstractCpsObject aCps : aUpperNode.getNodes()) {
			if (aCps instanceof HolonObject) holonObjectList.add((HolonObject) aCps);
			else if (aCps instanceof CpsNode) nodeList.add((CpsNode) aCps);
			else if (aCps instanceof HolonSwitch) switchList.add((HolonSwitch) aCps);
			else if(aCps instanceof CpsUpperNode) {
				addUpperObjects((CpsUpperNode)aCps);
				uppderNodeList.add((CpsUpperNode)aCps);
			}
			inGroupObjects.put(aCps, aUpperNode);
		}
		for (CpsEdge edge : aUpperNode.getNodeEdges()) {
			this.cableList.add(new IntermediateCableWithState(edge, CableState.Working));
			inGroupEdges.put(edge, aUpperNode);
		}
		for (CpsEdge edge : aUpperNode.getOldEdges()) {
			this.cableList.add(new IntermediateCableWithState(edge, CableState.Working));
			inGroupEdges.put(edge, aUpperNode);
		}
	}
	
	public ArrayList<HolonObject> getHolonObjectList() {
		return holonObjectList;
	}
	public void setHolonObjectList(ArrayList<HolonObject> holonObjectList) {
		this.holonObjectList = holonObjectList;
	}
	public ArrayList<IntermediateCableWithState> getEdgeList() {
		return cableList;
	}
	public void setEdgeList(ArrayList<IntermediateCableWithState> cableList) {
		this.cableList = cableList;
	}
	public ArrayList<CpsNode> getNodeList() {
		return nodeList;
	}
	public void setNodeList(ArrayList<CpsNode> nodeList) {
		this.nodeList = nodeList;
	}
	public ArrayList<HolonSwitch> getSwitchList() {
		return switchList;
	}
	public void setSwitchList(ArrayList<HolonSwitch> switchList) {
		this.switchList = switchList;
	}

	public ArrayList<CpsUpperNode> getUppderNodeList() {
		return uppderNodeList;
	}

	public HashMap<AbstractCpsObject, CpsUpperNode> getInGroupObjects() {
		return inGroupObjects;
	}

	public HashMap<CpsEdge, CpsUpperNode> getInGroupEdges() {
		return inGroupEdges;
	}
	
}
