#ifndef CONFIG_H
#define CONFIG_H

#include <stddef.h>

#include <lua.h>
#include <raylib.h>

#include <xkbcommon/xkbcommon.h>

typedef struct {
	xkb_keysym_t sym;
	uint32_t mods_mask;
	int action_ref;
} BindingRef;

typedef struct {
	struct {
		struct {
			char *xkb_options;
		} keyboard;
		struct {
			bool invert_x;
			bool invert_y;
		} mouse;
	} input;

	struct {
		BindingRef *items;
		size_t count;
	} keybindings;

	struct {
		Vector3 offset;
		float radius;
		float window_scale;
	} space;

	struct {
		bool enabled;
		bool lazy;
	} xwayland;

	struct {
		struct {
			int size;
			float font_size;
		} hud;
		struct {
			Vector2 resolution;
		} virtual;
	} displays;

	char const *cubemap;
} Config;

char const *get_config_path(void);

int config_load_ref(lua_State *L, int idx, Config *out);
void config_unref(lua_State *L, Config *cfg);
void config_trigger_ref(lua_State *L, Config *cfg, int ref);

struct ConfigManager {
	lua_State *L;
	Config cfg;
	char *path;
};
typedef struct ConfigManager ConfigManager;

ConfigManager *config_manager_create(char const *path);
void config_manager_destroy(ConfigManager *cm);

int config_manager_reload(ConfigManager *cm);

lua_State *config_manager_lua(ConfigManager *cm);
Config const *config_manager_get(ConfigManager *cm);
char const *config_manager_path(ConfigManager *cm);

#endif // CONFIG_H
