/*
 * DWN - Desktop Window Manager
 * retoor <retoor@molodetz.nl>
 * AI Integration (OpenRouter API)
 */

#ifndef DWN_AI_H
#define DWN_AI_H

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

/* Forward declarations for libcurl types */
struct curl_slist;
struct Curl_easy;
typedef struct Curl_easy DWN_CURL;

typedef enum {
    AI_STATE_IDLE,
    AI_STATE_PENDING,
    AI_STATE_COMPLETED,
    AI_STATE_ERROR
} AIState;

typedef struct AIRequest {
    char *prompt;
    char *response;
    AIState state;
    void (*callback)(struct AIRequest *req);
    void *user_data;
    struct AIRequest *next;
    struct curl_slist *headers;    /* Stored for proper cleanup */
    struct Curl_easy *curl_handle; /* Stored for cancellation */
} AIRequest;

typedef struct {
    char focused_window[256];
    char focused_class[64];
    char workspace_windows[1024];
    int window_count;
} AIContext;

bool ai_init(void);
void ai_cleanup(void);
bool ai_is_available(void);

AIRequest *ai_send_request(const char *prompt, void (*callback)(AIRequest *));
void ai_cancel_request(AIRequest *req);
void ai_process_pending(void);

void ai_update_context(void);
const char *ai_analyze_task(void);
const char *ai_suggest_window(void);
const char *ai_suggest_app(void);

void ai_show_command_palette(void);
void ai_execute_command(const char *command);

void ai_auto_organize_workspace(void);
void ai_suggest_layout(void);
void ai_analyze_workflow(void);

bool ai_should_show_notification(const char *app, const char *summary);
int ai_notification_priority(const char *app, const char *summary);

void ai_monitor_performance(void);
const char *ai_performance_suggestion(void);

typedef struct {
    char title[256];
    char url[512];
    char snippet[1024];
    float score;
} ExaSearchResult;

typedef struct ExaRequest {
    char *query;
    ExaSearchResult results[10];
    int result_count;
    int state;
    void (*callback)(struct ExaRequest *req);
    void *user_data;
    struct ExaRequest *next;
    struct curl_slist *headers;    /* Stored for proper cleanup */
    struct Curl_easy *curl_handle; /* Stored for cancellation */
} ExaRequest;

bool exa_is_available(void);
ExaRequest *exa_search(const char *query, void (*callback)(ExaRequest *));
void exa_process_pending(void);
void exa_show_app_launcher(void);

#endif
