/*
 * DWN - Desktop Window Manager
 * retoor <retoor@molodetz.nl>
 * Configuration system
 */

#ifndef DWN_CONFIG_H
#define DWN_CONFIG_H

#include "dwn.h"
#include <stdbool.h>

typedef struct {
    unsigned long panel_bg;
    unsigned long panel_fg;
    unsigned long workspace_active;
    unsigned long workspace_inactive;
    unsigned long workspace_urgent;
    unsigned long title_focused_bg;
    unsigned long title_focused_fg;
    unsigned long title_unfocused_bg;
    unsigned long title_unfocused_fg;
    unsigned long border_focused;
    unsigned long border_unfocused;
    unsigned long notification_bg;
    unsigned long notification_fg;
} ColorScheme;

struct Config {
    char terminal[128];
    char launcher[128];
    char file_manager[128];
    FocusMode focus_mode;
    int focus_follow_delay_ms;
    bool show_decorations;

    int border_width;
    int title_height;
    int panel_height;
    int gap;
    char font_name[128];
    ColorScheme colors;

    float default_master_ratio;
    int default_master_count;
    LayoutType default_layout;

    bool top_panel_enabled;
    bool bottom_panel_enabled;

    char openrouter_api_key[256];
    char exa_api_key[256];
    char ai_model[64];
    bool ai_enabled;

    char config_path[512];
    char log_path[512];

    bool autostart_enabled;
    bool autostart_xdg;
    char autostart_path[512];

    char services_path[512];
    bool api_enabled;
    int api_port;

    int demo_step_delay_ms;
    int demo_ai_timeout_ms;
    int demo_window_timeout_ms;

    /* Fade effects */
    float fade_speed;        /* Animation speed multiplier (0.1 - 3.0) */
    float fade_intensity;    /* Glow intensity (0.0 - 1.0) */

    char color_panel_bg[16];
    char color_panel_fg[16];
    char color_workspace_active[16];
    char color_workspace_inactive[16];
    char color_workspace_urgent[16];
    char color_title_focused_bg[16];
    char color_title_focused_fg[16];
    char color_title_unfocused_bg[16];
    char color_title_unfocused_fg[16];
    char color_border_focused[16];
    char color_border_unfocused[16];
    char color_notification_bg[16];
    char color_notification_fg[16];
};

Config *config_create(void);
void config_destroy(Config *cfg);
bool config_load(Config *cfg, const char *path);
bool config_reload(Config *cfg);
void config_set_defaults(Config *cfg);
void config_validate(Config *cfg);

const char *config_get_terminal(void);
const char *config_get_launcher(void);
int config_get_border_width(void);
int config_get_title_height(void);
int config_get_panel_height(void);
int config_get_gap(void);
const ColorScheme *config_get_colors(void);
float config_get_fade_speed(void);
float config_get_fade_intensity(void);
void config_set_fade_speed(float speed);
void config_set_fade_intensity(float intensity);

typedef void (*ConfigCallback)(const char *section, const char *key,
                               const char *value, void *user_data);
bool config_parse_ini(const char *path, ConfigCallback callback, void *user_data);

#endif
