/**
 * adblock.h - Adblocker integration for WebKit2GTK
 *
 * This module provides content filtering capabilities using
 * WebKitUserContentFilter to block ads and trackers.
 */

#ifndef EXTENSIONS_ADBLOCK_H
#define EXTENSIONS_ADBLOCK_H

#include <glib.h>
#include <webkit2/webkit2.h>

G_BEGIN_DECLS

/**
 * AdblockManager:
 *
 * Opaque structure representing the adblock manager.
 * Manages content filters and their lifecycle.
 */
typedef struct _AdblockManager AdblockManager;

/**
 * AdblockError:
 *
 * Error codes for adblock operations.
 */
typedef enum {
  ADBLOCK_ERROR_FILE_NOT_FOUND,
  ADBLOCK_ERROR_COMPILATION_FAILED,
  ADBLOCK_ERROR_STORE_FAILED,
  ADBLOCK_ERROR_INVALID_JSON,
  ADBLOCK_ERROR_IO_ERROR
} AdblockError;

#define ADBLOCK_ERROR (adblock_error_quark())
GQuark adblock_error_quark(void);

/**
 * AdblockCallback:
 * @manager: The AdblockManager instance
 * @success: TRUE if the operation succeeded
 * @error: A GError if the operation failed, or NULL
 * @user_data: User data passed to the original function
 *
 * Callback function called when filter compilation completes.
 */
typedef void (*AdblockCallback)(AdblockManager *manager, gboolean success,
                                GError *error, gpointer user_data);

/**
 * adblock_manager_new:
 * @store_path: Path to the content filter store directory (can be NULL for
 * default)
 *
 * Creates a new AdblockManager instance.
 *
 * Returns: A new AdblockManager, or NULL on failure. Free with
 * adblock_manager_free().
 */
AdblockManager *adblock_manager_new(const gchar *store_path);

/**
 * adblock_manager_free:
 * @manager: The AdblockManager to free
 *
 * Frees all resources associated with the AdblockManager.
 */
void adblock_manager_free(AdblockManager *manager);

/**
 * adblock_manager_load_from_file:
 * @manager: The AdblockManager instance
 * @filter_list_path: Path to the filter list file (e.g., easylist.txt)
 * @filter_identifier: Unique identifier for this filter (e.g., "easylist")
 * @callback: Callback to invoke when compilation completes
 * @user_data: User data to pass to the callback
 * @error: Return location for a GError, or NULL
 *
 * Asynchronously loads and compiles a filter list from a file.
 * The filter list should be in AdBlock format.
 *
 * Returns: TRUE if the operation was initiated successfully, FALSE otherwise
 */
gboolean adblock_manager_load_from_file(AdblockManager *manager,
                                        const gchar *filter_list_path,
                                        const gchar *filter_identifier,
                                        AdblockCallback callback,
                                        gpointer user_data, GError **error);

/**
 * adblock_manager_apply_to_web_view:
 * @manager: The AdblockManager instance
 * @web_view: The WebKitWebView to apply filters to
 * @error: Return location for a GError, or NULL
 *
 * Applies all compiled filters to the given WebView.
 * This should be called for each WebView instance.
 *
 * Returns: TRUE if successful, FALSE otherwise
 */
gboolean adblock_manager_apply_to_web_view(AdblockManager *manager,
                                           WebKitWebView *web_view,
                                           GError **error);

/**
 * adblock_manager_set_enabled:
 * @manager: The AdblockManager instance
 * @enabled: TRUE to enable blocking, FALSE to disable
 *
 * Enables or disables ad blocking globally for all WebViews
 * that have been configured with this manager.
 */
void adblock_manager_set_enabled(AdblockManager *manager, gboolean enabled);

/**
 * adblock_manager_is_enabled:
 * @manager: The AdblockManager instance
 *
 * Checks if ad blocking is currently enabled.
 *
 * Returns: TRUE if enabled, FALSE otherwise
 */
gboolean adblock_manager_is_enabled(AdblockManager *manager);

/**
 * adblock_manager_get_filter_count:
 * @manager: The AdblockManager instance
 *
 * Gets the number of loaded filters.
 *
 * Returns: The number of loaded filters
 */
guint adblock_manager_get_filter_count(AdblockManager *manager);

/**
 * adblock_manager_reload_filters:
 * @manager: The AdblockManager instance
 * @callback: Callback to invoke when reloading completes
 * @user_data: User data to pass to the callback
 *
 * Reloads all previously loaded filter lists.
 * Useful for updating filters without restarting the application.
 */
void adblock_manager_reload_filters(AdblockManager *manager,
                                    AdblockCallback callback,
                                    gpointer user_data);

G_END_DECLS

#endif /* EXTENSIONS_ADBLOCK_H */
