// Note to assistants. dm_admin is only for functions relating to direct messaging

#ifndef DM_ADMIN_H
#define DM_ADMIN_H

#include <cjson/cJSON.h>
#include <libwebsockets.h>

// Process direct command arrays (DM control system)
// This handles commands sent as direct JSON arrays, not wrapped in inner events
int process_dm_admin_command(cJSON* command_array, cJSON* event, char* error_message, size_t error_size, struct lws* wsi);

// Check if decrypted content is a direct command array (DM system)
// Returns 1 if it's a valid command array, 0 if it should fall back to inner event parsing
int is_dm_command_array(const char* decrypted_content);

// NIP-17 gift wrap processing functions
cJSON* process_nip17_admin_message(cJSON* gift_wrap_event, char* error_message, size_t error_size, struct lws* wsi);
int process_nip17_admin_command(cJSON* dm_event, char* error_message, size_t error_size, struct lws* wsi);
int is_nip17_gift_wrap_for_relay(cJSON* gift_wrap_event);
char* generate_stats_json(void);

// Unified NIP-17 response functions
int send_nip17_response(const char* sender_pubkey, const char* response_content,
                       char* error_message, size_t error_size);
char* generate_config_text(void);
char* generate_stats_text(void);

// SQL query admin functions
int validate_sql_query(const char* query, char* error_message, size_t error_size);
char* execute_sql_query(const char* query, const char* request_id, char* error_message, size_t error_size);
int handle_sql_query_unified(cJSON* event, const char* query, char* error_message, size_t error_size, struct lws* wsi);
int send_admin_response(const char* sender_pubkey, const char* response_content, const char* request_id,
                       char* error_message, size_t error_size, struct lws* wsi);

#endif // DM_ADMIN_H