package model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Observable;

import command.CommandInterface;
import controller.ParseTreeNode;
import javafx.scene.paint.Color;

public class Data extends Observable implements Data_Turtle_Interface{

	private List<SlogoObjects> myTurtles = new ArrayList<SlogoObjects>();
	private List<Trail> myTrails = new ArrayList<Trail>();
	private boolean myError = false;
	private String myErrorMessage;
	private List<String> myUserHistory;
	private Map<String, Double> myVariableMap;
	private Map<String, ParseTreeNode<CommandInterface>> myUserCommandMap;
	private Color myColor;

	public Data() {
		Turtle defaultTurtle = new Turtle();
		myTurtles.add(defaultTurtle);
		myTrails.add(defaultTurtle.getTrail());

		myUserHistory = new ArrayList<String>();
		myVariableMap = new HashMap<String, Double>();
		myUserCommandMap = new HashMap<String, ParseTreeNode<CommandInterface>>();

		setMyColor(Color.ALICEBLUE);
	}

	@Override
	public void setTurtle(int turtleId, SlogoObjects turtle){
		myTurtles.set(turtleId, turtle);
		setChanged();
		notifyObservers();
	}

	@Override
	public SlogoObjects getTurtle(int turtleId){
		return myTurtles.get(turtleId);
	}

	public Trail getTrail(int turtleId) {
		return myTrails.get(turtleId);
	}

	public String getErrorMessage() {
		return myErrorMessage;
	}

	public void setErrorMessage(String errorMessage) {
		this.myErrorMessage = errorMessage;
		setChanged();
		notifyObservers();
	}

	public boolean isError() {
		return myError;
	}

	public void setError(boolean error) {
		this.myError = error;
		setChanged();
		notifyObservers();
	}

	public List<String> getUserHistory() {
		return myUserHistory;
	}

	public void setUserHistory(List<String> userHistory) {
		this.myUserHistory = userHistory;
		setChanged();
		notifyObservers();
	}

	public void addCommandToHistory(String s) {
		myUserHistory.add(s);
		setChanged();
		notifyObservers();
	}

	public Map<String, Double> getVariableMap() {
		return myVariableMap;
	}

	public void setVariableMap(Map<String, Double> variableMap) {
		this.myVariableMap = variableMap;
	}
	@Override
	public void updateVaraibleMap(String varName, Double value){
		myVariableMap.put(varName, value);
		setChanged();
		notifyObservers();
	}

	public Map<String, ParseTreeNode<CommandInterface>> getUserCommandMap() {
		return myUserCommandMap;
	}

	public void setUserCommandMap(Map<String, ParseTreeNode<CommandInterface>> userCommandMap) {
		this.myUserCommandMap = userCommandMap;
	}

	public void setMyColor(Color color){
		myColor = color;
		setChanged();
		notifyObservers();
	}

	public Color getMyColor(){
		return myColor;

	}


}

@@ -307,18 +307,19 @@
 nterface
+ 
 %7B%0A
-
 %0A%09privat
@@ -680,16 +680,54 @@
 myColor;
+%0A%09private double commandReturnedValue;
 %0A%0A%09publi
@@ -1124,16 +1124,17 @@
  turtle)
+ 
 %7B%0A%09%09myTu
@@ -1258,16 +1258,17 @@
 urtleId)
+ 
 %7B%0A%09%09retu
@@ -1562,32 +1562,237 @@
 bservers();%0A%09%7D%0A%0A
+%09public void setCommandReturnedValue(double value) %7B%0A%09%09commandReturnedValue = value;%0A%09%09setChanged();%0A%09%09notifyObservers();%0A%0A%09%7D%0A%0A%09public double getCommandReturnedValue() %7B%0A%09%09return commandReturnedValue;%0A%09%7D%0A%0A
 %09public boolean 
@@ -2417,16 +2417,17 @@
 Map;%0A%09%7D%0A
+%0A
 %09@Overri
@@ -2489,16 +2489,17 @@
 e value)
+ 
 %7B%0A%09%09myVa
@@ -2852,16 +2852,17 @@
 r color)
+ 
 %7B%0A%09%09myCo
@@ -2941,16 +2941,17 @@
 yColor()
+ 
 %7B%0A%09%09retu
@@ -2967,11 +2967,10 @@
 r;%0A%0A
+
 %09%7D%0A%0A
-%0A
 %7D%0A

all commands