#include "Command.h"
#include "Door.h"
#include "Level.h"
#include "List.h"

using namespace std;

const std::string SetDoorLockCommand::_id = "setDoorLock";

SetDoorLockCommand::SetDoorLockCommand(Door *door, bool locked)
:_door(door),_locked(locked)
{
}

SetDoorLockCommand::SetDoorLockCommand(List *command)
{
	command = command->rest();
	_door = (Door*)Level::instance()->getObject(command->firstString());
	command = command->rest();
	string locked = command->firstString();
	if(locked == "true")
		_locked = true;
	else
		_locked = false;
}

void SetDoorLockCommand::execute()
{
 	_door->setLock(_locked);
}

std::string SetDoorLockCommand::getString()
{
	List *command = new List();
	command->snoc(new Atom(_id));
	command->snoc(new Atom(_door->id()));
	if(_locked)
		command->snoc(new Atom("true"));
	else
		command->snoc(new Atom("false"));
	string commandString = command->getString();
	delete command;

	return commandString;
}