<?php
/**
 * Plugin Name:       Seekmodo Search
 * Plugin URI:        https://seekmodo.com/plugins/wordpress
 * Description:       AI-powered search for WordPress (and WooCommerce product search, when active). Routes site search through the Seekmodo platform at mcp.seekmodo.com. Two activatable verticals: `content` (WP core) and `commerce` (WooCommerce). Optional drop-in typeahead dropdown UI (v0.4.0+). Native LIKE / Woo query stays permanently armed as a graceful fallback. Requires a Seekmodo account; every plan ships with a 14-day free trial.
 * Version:           0.11.7
 * Requires at least: 6.2
 * Tested up to:      7.0
 * Requires PHP:      8.0
 * Author:            Numinix
 * Author URI:        https://numinix.com
 * License:           GPL-2.0-or-later
 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain:       seekmodo
 * Domain Path:       /languages
 *
 * @package Numinix\SeekmodoWordPress
 */

declare(strict_types=1);

if (!defined('ABSPATH')) {
    exit;
}

define('SEEKMODO_WP_VERSION', '0.11.7');
define('SEEKMODO_WP_PLUGIN_FILE', __FILE__);
define('SEEKMODO_WP_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('SEEKMODO_WP_PLUGIN_URL', plugin_dir_url(__FILE__));
define('SEEKMODO_WP_PLUGIN_BASENAME', plugin_basename(__FILE__));

// Default gateway URL; remotely overridable via tenant.snapshot from admin.seekmodo.com.
if (!defined('SEEKMODO_WP_GATEWAY_URL')) {
    define('SEEKMODO_WP_GATEWAY_URL', 'https://mcp.seekmodo.com');
}

// Composer autoloader for vendored runtime deps (numinix/seekmodo-connector
// SDK, guzzlehttp/psr7, psr/http-* contracts). The 0.7.0 SDK-adoption ship
// inadvertently omitted this require — without it the legacy PSR-4-ish
// autoloader below only resolved Numinix\SeekmodoWordPress\* and any call
// into \Numinix\SeekmodoSdk\* from the new Sdk\Bootstrap helper or its
// adapters would fatal at class-resolution time. Restored as part of
// v0.7.1 with no other code changes (the legacy gateway path is still the
// active storefront codepath, but the SDK now actually works when called).
$seekmodoVendorAutoload = SEEKMODO_WP_PLUGIN_DIR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
if (is_file($seekmodoVendorAutoload)) {
    require_once $seekmodoVendorAutoload;
}
unset($seekmodoVendorAutoload);

// PSR-4-ish autoloader for src/Numinix/SeekmodoWordPress/... mapped to src/...
// Kept as a safety net so the plugin keeps working even if vendor/ is
// stripped (e.g. during a partial deploy or hot-edit by an operator).
spl_autoload_register(static function (string $class): void {
    $prefix = 'Numinix\\SeekmodoWordPress\\';
    $len    = strlen($prefix);
    if (strncmp($prefix, $class, $len) !== 0) {
        return;
    }
    $relative = substr($class, $len);
    $relPath  = str_replace('\\', DIRECTORY_SEPARATOR, $relative) . '.php';
    $file     = SEEKMODO_WP_PLUGIN_DIR . 'src' . DIRECTORY_SEPARATOR . $relPath;
    if (is_file($file)) {
        require_once $file;
    }
});

// Procedural helper facades (numinix_seekmodo_* function family).
require_once SEEKMODO_WP_PLUGIN_DIR . 'src/Helpers/functions.php';

register_activation_hook(__FILE__, [Numinix\SeekmodoWordPress\Bootstrap::class, 'activate']);
register_deactivation_hook(__FILE__, [Numinix\SeekmodoWordPress\Bootstrap::class, 'deactivate']);

add_action('plugins_loaded', [Numinix\SeekmodoWordPress\Bootstrap::class, 'boot'], 5);
