<?php
namespace AI_BotKit;

use AI_BotKit\Admin\Admin;
use AI_BotKit\Public\Shortcode_Handler;
use AI_BotKit\Integration\REST_API;

/**
 * The core plugin class.
 *
 * This is used to define internationalization, admin-specific hooks, and
 * public-facing site hooks.
 *
 * @package AI_BotKit
 */
class AI_BotKit {

    /**
     * Integration components
     */
    private $rest_api;
    private $api_handler;

    private $admin;
    private $shortcode_handler;
    private $product_button;

    /**
     * Initialize the plugin
     */
    public function __construct() {
        $this->load_dependencies();
        $this->setup_components();
        $this->define_admin_hooks();
        $this->define_public_hooks();
    }

    /**
     * Load required dependencies
     */
    private function load_dependencies(): void {

        // Integration components
        require_once AI_BOTKIT_INCLUDES_DIR . 'integration/class-rest-api.php';
        require_once AI_BOTKIT_INCLUDES_DIR . 'integration/class-api-handler.php';
        require_once AI_BOTKIT_INCLUDES_DIR . 'integration/class-pep-detector.php';
        require_once AI_BOTKIT_INCLUDES_DIR . 'integration/class-product-content-enricher.php';

        // Admin and public
        require_once AI_BOTKIT_INCLUDES_DIR . 'admin/class-admin.php';
        require_once AI_BOTKIT_INCLUDES_DIR . 'admin/class-ajax-handler.php';
        require_once AI_BOTKIT_INCLUDES_DIR . 'public/class-shortcode-handler.php';
        require_once AI_BOTKIT_INCLUDES_DIR . 'public/class-product-button.php';
    }

    /**
     * Setup plugin components
     */
    private function setup_components(): void {


        // Initialize integration components
        $this->rest_api = new REST_API();
        $this->api_handler = new \AI_BotKit\Integration\API_Handler();

        // Register content enrichment filter
        \AI_BotKit\Integration\Product_Content_Enricher::register();

        // Initialize interface components
        $this->admin = new Admin($this->get_plugin_name(), $this->get_version());
        $this->shortcode_handler = new Shortcode_Handler();
        $this->product_button = new \AI_BotKit\Public\Product_Button();
    }

    /**
     * Register admin hooks
     */
    private function define_admin_hooks(): void {
        // Admin menu and pages
        add_action('admin_menu', [$this->admin, 'add_plugin_admin_menu']);

        // Admin assets
        add_action('admin_enqueue_scripts', [$this->admin, 'enqueue_styles']);
        add_action('admin_enqueue_scripts', [$this->admin, 'enqueue_scripts']);

        // PEP detector admin notice (removed — feature now works without PEP)
    }

    /**
     * Register public hooks
     */
    private function define_public_hooks(): void {
        add_action('wp_footer', [$this->shortcode_handler, 'render_sitewide_chatbot']);

    }

    /**
     * Run the plugin
     */
    public function run(): void {
        do_action('ai_botkit_init', $this);
    }


    /**
     * The name of the plugin used to uniquely identify it within the context of
     * WordPress and to define internationalization functionality.
     *
     * @return string The name of the plugin.
     */
    public function get_plugin_name(): string {
        return 'ai-botkit-for-lead-generation';
    }

    /**
     * Retrieve the version number of the plugin.
     *
     * @return string The version number of the plugin.
     */
    public function get_version(): string {
        return defined('AI_BOTKIT_VERSION') ? AI_BOTKIT_VERSION : '1.0.0';
    }
} 