#ifndef COMMANDMANAGER_H
#define COMMANDMANAGER_H

#include <queue>
#include <string>

class Command;
class List;

class CommandTime
{
public:
	Command* c;
	int time;

	bool operator<(const CommandTime &rhs) const {return time < rhs.time;}
	bool operator>(const CommandTime &rhs) const {return time > rhs.time;}
};

class CommandManager
{
public:
	static CommandManager* instance();
	
	void startRecording();
	void stopRecording();
	void saveRecording(std::string filename);
	
	void startPlaying(std::priority_queue<CommandTime,std::vector<CommandTime>,std::greater<CommandTime> > &commands);
	void startPlaying(List *commands);
	void startPlaying(std::string filename);
	void stopPlaying();

	void startTimestep();

	void flush();

	void execute(Command *command);
	void execute(std::queue<Command*> commands);
private:
	CommandManager();
	std::priority_queue<CommandTime,std::vector<CommandTime>,std::greater<CommandTime> > _demoCommands;
	std::priority_queue<CommandTime,std::vector<CommandTime>,std::greater<CommandTime> > _playCommands;

	bool _flush;
	bool _recording;
	bool _playing;

	static CommandManager *_instance;

	int _demoTime;
	int _playTime;
};

#endif