/*
 * retoor <retoor@molodetz.nl>
 * DWN - Desktop Window Manager
 * WebSocket API with event subscription system
 */

#ifndef DWN_API_H
#define DWN_API_H

#include <stdbool.h>
#include <X11/Xlib.h>

typedef enum {
    EVENT_WINDOW_CREATED,
    EVENT_WINDOW_DESTROYED,
    EVENT_WINDOW_FOCUSED,
    EVENT_WINDOW_UNFOCUSED,
    EVENT_WINDOW_MOVED,
    EVENT_WINDOW_RESIZED,
    EVENT_WINDOW_MINIMIZED,
    EVENT_WINDOW_RESTORED,
    EVENT_WINDOW_MAXIMIZED,
    EVENT_WINDOW_UNMAXIMIZED,
    EVENT_WINDOW_FULLSCREEN,
    EVENT_WINDOW_UNFULLSCREEN,
    EVENT_WINDOW_FLOATING,
    EVENT_WINDOW_UNFLOATING,
    EVENT_WINDOW_TITLE_CHANGED,
    EVENT_WINDOW_RAISED,
    EVENT_WINDOW_LOWERED,

    EVENT_WORKSPACE_SWITCHED,
    EVENT_WORKSPACE_WINDOW_ADDED,
    EVENT_WORKSPACE_WINDOW_REMOVED,
    EVENT_WORKSPACE_LAYOUT_CHANGED,
    EVENT_WORKSPACE_MASTER_RATIO_CHANGED,
    EVENT_WORKSPACE_MASTER_COUNT_CHANGED,
    EVENT_WORKSPACE_ARRANGED,

    EVENT_LAYOUT_CHANGED,

    EVENT_KEY_PRESSED,
    EVENT_KEY_RELEASED,
    EVENT_SHORTCUT_TRIGGERED,

    EVENT_MOUSE_MOVED,
    EVENT_MOUSE_BUTTON_PRESSED,
    EVENT_MOUSE_BUTTON_RELEASED,

    EVENT_DRAG_STARTED,
    EVENT_DRAG_ENDED,

    EVENT_SHOW_DESKTOP_TOGGLED,

    EVENT_NOTIFICATION_SHOWN,
    EVENT_NOTIFICATION_CLOSED,

    EVENT_FADE_SPEED_CHANGED,
    EVENT_FADE_INTENSITY_CHANGED,

    EVENT_WINDOW_SNAPPED,
    EVENT_AUDIO_VOLUME_CHANGED,
    EVENT_AUDIO_MUTE_TOGGLED,
    EVENT_PANEL_VISIBILITY_CHANGED,
    EVENT_CONFIG_RELOADED,
    EVENT_AI_RESPONSE_RECEIVED,
    EVENT_EXA_SEARCH_COMPLETED,
    EVENT_NEWS_ARTICLE_CHANGED,
    EVENT_DEMO_STARTED,
    EVENT_DEMO_STOPPED,
    EVENT_DEMO_PHASE_CHANGED,
    EVENT_TUTORIAL_STARTED,
    EVENT_TUTORIAL_STOPPED,

    EVENT_COUNT
} ApiEventType;

void api_init(void);
void api_process(void);
void api_cleanup(void);
void api_handle_json_command(const char *json_str);

const char *api_event_name(ApiEventType type);

void api_emit_window_created(Window window, const char *title, const char *class_name, int workspace);
void api_emit_window_destroyed(Window window, const char *title, int workspace);
void api_emit_window_focused(Window window, const char *title, Window prev_window);
void api_emit_window_unfocused(Window window, const char *title);
void api_emit_window_moved(Window window, int old_x, int old_y, int new_x, int new_y);
void api_emit_window_resized(Window window, int old_w, int old_h, int new_w, int new_h);
void api_emit_window_minimized(Window window);
void api_emit_window_restored(Window window);
void api_emit_window_maximized(Window window, bool maximized);
void api_emit_window_fullscreen(Window window, bool fullscreen);
void api_emit_window_floating(Window window, bool floating);
void api_emit_window_title_changed(Window window, const char *old_title, const char *new_title);
void api_emit_window_raised(Window window);
void api_emit_window_lowered(Window window);

void api_emit_workspace_switched(int old_workspace, int new_workspace);
void api_emit_workspace_window_added(int workspace, Window window);
void api_emit_workspace_window_removed(int workspace, Window window);
void api_emit_workspace_layout_changed(int workspace, int old_layout, int new_layout);
void api_emit_workspace_master_ratio_changed(int workspace, float old_ratio, float new_ratio);
void api_emit_workspace_master_count_changed(int workspace, int old_count, int new_count);
void api_emit_workspace_arranged(int workspace, int layout);

void api_emit_key_pressed(unsigned int keycode, unsigned int keysym, unsigned int modifiers);
void api_emit_key_released(unsigned int keycode, unsigned int keysym, unsigned int modifiers);
void api_emit_shortcut_triggered(const char *name, const char *description);

void api_emit_mouse_moved(int x, int y);
void api_emit_mouse_button_pressed(int button, int x, int y);
void api_emit_mouse_button_released(int button, int x, int y);

void api_emit_drag_started(Window window, bool is_resize);
void api_emit_drag_ended(Window window, bool is_resize);

void api_emit_show_desktop_toggled(bool shown);

void api_emit_notification_shown(unsigned int id, const char *summary, const char *body);
void api_emit_notification_closed(unsigned int id);

void api_emit_fade_speed_changed(float old_speed, float new_speed);
void api_emit_fade_intensity_changed(float old_intensity, float new_intensity);

void api_emit_window_snapped(Window window, int horizontal, int vertical);
void api_emit_audio_volume_changed(int old_volume, int new_volume);
void api_emit_audio_mute_toggled(bool muted);
void api_emit_panel_visibility_changed(const char *panel, bool visible);
void api_emit_config_reloaded(void);
void api_emit_ai_response_received(const char *prompt, const char *response, bool success);
void api_emit_exa_search_completed(const char *query, int result_count, bool success);
void api_emit_news_article_changed(int old_index, int new_index, const char *title);
void api_emit_demo_started(void);
void api_emit_demo_stopped(void);
void api_emit_demo_phase_changed(int phase, const char *phase_name);
void api_emit_tutorial_started(void);
void api_emit_tutorial_stopped(void);

#endif
