package background.systemVariables;

import java.util.ArrayList;

import background.VariableManager;

public class TableVariable {
	private ArrayList<ArrayList<SimpleVariable>> innerVariables;
	public String name;
	public Boolean vizualize;
	public int sizeX;
	public int sizeY;
	private String type;
	public int posunX = 0;
	public int posunY = 0;
	
	public TableVariable(int p1,int s1, int p2, int s2, String t, VariableManager vm) {
		posunX = p1;
		posunY = p2;
		sizeX = s1-posunX;
		sizeY = s2-posunY;
		type = t;
		innerVariables = new ArrayList<ArrayList<SimpleVariable>>();
		for (int i=0; i<sizeY; i++) innerVariables.add(new ArrayList<SimpleVariable>());
		
		for (int i=0; i<sizeY; i++) {		
			for (int j=0; j<sizeX; j++) {
				innerVariables.get(i).add(vm.getNewVariableOfType(type, vm.getDefaultValueForType(type)));
			}
		}		
	}
	
	public TableVariable(int s1, int s2, String t, VariableManager vm) {
		sizeX = s1;
		sizeY = s2;
		type = t;
		innerVariables = new ArrayList<ArrayList<SimpleVariable>>();
		for (int i=0; i<sizeY; i++) innerVariables.add(new ArrayList<SimpleVariable>());
		
		for (int i=0; i<sizeY; i++) {		
			for (int j=0; j<sizeX; j++) {
				innerVariables.get(i).add(vm.getNewVariableOfType(type, vm.getDefaultValueForType(type)));
			}
		}
	}

	public TableVariable(int s1, int s2, String t) {
		sizeX = s1;
		sizeY = s2;
		type = t;
		innerVariables = new ArrayList<ArrayList<SimpleVariable>>();
		for (int i=1; i<=sizeY; i++) innerVariables.add(new ArrayList<SimpleVariable>());
		
		for (int i=1; i<=sizeY; i++) {		
			for (int j=1; j<=sizeX; j++) {
				innerVariables.get(i).add(new SimpleVariable());
			}
		}
	}

	
	public String getType() {
		return type;
	}
	
	public void setVizualize(Boolean b) {
		vizualize = b;
	}

	public SimpleVariable getNth(int i, int j) {		
		SimpleVariable result = innerVariables.get(i-posunY).get(j-posunX);
		return result;
	}
	
	public void updateNth(int i, int j, SimpleVariable val) {
		if (val.getType().equals(type)) {
			innerVariables.get(i-posunY).get(j-posunX).initialized = true;
			innerVariables.get(i-posunY).get(j-posunX).setValue(val.getValue("string"));
		}
	}

	
	
}
