#include "InputHandler.h"

#include <iostream>

InputHandler::InputHandler() {
	W = new WCommand();
	A = new ACommand();
	S = new SCommand();
	D = new DCommand();
	quit = new QuitCommand();
}

InputHandler::~InputHandler() {
	//Free all Commands
	delete W;
	delete A;
	delete S;
	delete D;
	delete quit;
}

Command* InputHandler::handleInput(SDL_Event *event) {
	if(event == NULL) {
		return NULL;
	}
	switch (event->type) {
		case SDL_QUIT:
		    return quit;
			break;
		case SDL_KEYDOWN: 
			std::cout << "The Key " << SDL_GetKeyName(event->key.keysym.sym) << " has been pressed!" << std::endl;
			return NULL;
			break;
		case SDL_KEYUP: 
			std::cout << "The Key " << SDL_GetKeyName(event->key.keysym.sym) << " has been released!" << std::endl;
			switch(event->key.keysym.sym) {
				case SDLK_w:
				return W;
				break;
				case SDLK_a:
				return A;
				break;
				case SDLK_s:
				return S;
				break;
				case SDLK_d:
				return D;
				break;
				default: break;
			}
			return NULL;
			break;
		default: 
		return NULL;
		break;
	}
}
