package background.commands;

import background.CommandManager;

public class Read extends Command {
	
	public String name;	
	
	public Boolean array = false;
	public Boolean table = false;

	public Read(CommandManager cm) {super(cm); }
	public Read(Boolean viz, CommandManager cm) {super(viz, cm);}

	@Override
	public String getType() {
		return "Read";
	}
	
	@Override
	public void applyCommand() {
		String value = commandManager.ioManager.getNextInput();
		
		if (value.isEmpty()) {
			commandManager.errorManager.errorHappened("MissingInput");
		} else {
			if (table) variableManager.updateTableVariable(name, index2.getTreeValue().intValue(), index.getTreeValue().intValue(), value);
			else if (array) variableManager.updateArrayVariable(name, index.getTreeValue().intValue(), value);
			else variableManager.updateVariable(name, value);	
		}
			
	}
	
	
	
}
