#ifndef _PIUMA_LIB_EVENT_H_
#define _PIUMA_LIB_EVENT_H_

#include "types.h"
#include "math.h"

// Mouse events
// Keyboard events
// Window events (resize, hide, focus)
// Quit
// Other OS events (signals?)


enum Event_Type
{
	EVENT_NONE,

	EVENT_QUIT,

	EVENT_MOUSE_MOVE,
	EVENT_KEY,

	EVENT_RESIZE,
	EVENT_FOCUS,
	EVENT_UNFOCUS,

	EVENT_TEXT,

	EVENT_COUNT
};



// @Performance: a lot of this codes are sequential in Linux. Check with other OSs if that's the case. If it is, we can have faster mapping by subtracting and adding an offset.
enum Key_Code
{
	KEY_UNKNOWN = 0,

	// @Correctness: check all ascii characters that are on a keyboard
	KEY_ENTER  = '\r',
	KEY_ESCAPE = '\e',
	KEY_BACKSPACE = '\b',
	KEY_TAB = '\t',
	KEY_SPACE = ' ',
	KEY_EXCLAMATION = '!',
	KEY_DOUBLE_QUOTE = '"',
	KEY_HASH = '#',
	KEY_PERCENT = '%',
	KEY_DOLLAR = '$',
	KEY_AMPERSAND = '&',
	KEY_SINGLE_QUOTE = '\'',
	KEY_LEFT_PARENTHESIS = '(',
	KEY_RIGHT_PARENTHESIS = ')',
	KEY_ASTERISK = '*',
	KEY_PLUS = '+',
	KEY_COMMA = ',',
	KEY_MINUS = '-',
	KEY_PERIOD = '.',
	KEY_SLASH = '/',
	KEY_0 = '0',
	KEY_1 = '1',
	KEY_2 = '2',
	KEY_3 = '3',
	KEY_4 = '4',
	KEY_5 = '5',
	KEY_6 = '6',
	KEY_7 = '7',
	KEY_8 = '8',
	KEY_9 = '9',
	KEY_COLON = ':',
	KEY_SEMICOLON = ';',
	KEY_LESS = '<',
	KEY_EQUALS = '=',
	KEY_GREATER = '>',
	KEY_QUESTION = '?',
	KEY_AT = '@',
	KEY_LEFT_BRACKET = '[',
	KEY_RIGHT_BRACKET = ']',
	KEY_BACKSLASH = '\\',
	KEY_CARET = '^',
	KEY_UNDERSCORE = '_',
	KEY_BACKQUOTE = '`',
	KEY_A = 'A',
	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EEL_DOWN,
	KEY_MOUSE_4,
	KEY_MOUSE_5,

	// @Correctness: check for more keys in: USB spec, linux libinput/x11/wayland/whatever, windows win32
};

struct Event_Key
{
	bool pressed;
	Key_Code key_code;
};


struct Event_Mouse_Move
{
	bool relative;
	union
	{
		v2 position;
		v2 delta;
	};
};


struct Event_Resize
{
	s32 width, height;
};


struct Event_Text
{
	char data[16]; // @Correctness: We have a bug if the os sends text that is longer
};


struct Event
{
	Event_Type type;

	union
	{
		Event_Key          key;
		Event_Mouse_Move   mouse_move;
		Event_Resize       resize;
		Event_Text         text;
	};
};


#endif
