<?php
/**
 * Plugin Name: ContentReply AI
 * Plugin URI: https://wordpress.org/plugins/contentreply-ai/
 * Description: An AI-powered support chatbot that learns from your site content and answers visitor questions instantly. Supports Groq (free), Google Gemini, and OpenAI.
 * Version: 1.0.0
 * Author: Radixweb
 * Author URI: https://radixweb.com/about-us
 * Developer: Laxman Prajapati
 * Developer URI: https://profiles.wordpress.org/laxman-prajapati/
 * License: GPL-2.0+
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: contentreply-ai
 * Domain Path: /languages
 * Requires at least: 6.0
 * Requires PHP: 7.4
 *
 * @package ContentReply_AI
 */

// Prevent direct access
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

// Plugin constants
define( 'WPSC_VERSION', '1.0.0' );
define( 'WPSC_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'WPSC_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'WPSC_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );

// Include core files
require_once WPSC_PLUGIN_DIR . 'includes/class-activator.php';
require_once WPSC_PLUGIN_DIR . 'includes/class-indexer.php';
require_once WPSC_PLUGIN_DIR . 'includes/class-ai-provider.php';
require_once WPSC_PLUGIN_DIR . 'includes/class-chat-handler.php';
require_once WPSC_PLUGIN_DIR . 'includes/class-admin.php';
require_once WPSC_PLUGIN_DIR . 'public/class-public.php';

/**
 * Plugin activation hook
 */
function wpsc_activate() {
    WPSC_Activator::activate();
}
register_activation_hook( __FILE__, 'wpsc_activate' );

/**
 * Plugin deactivation hook
 */
function wpsc_deactivate() {
    WPSC_Activator::deactivate();
}
register_deactivation_hook( __FILE__, 'wpsc_deactivate' );

/**
 * Initialize the plugin
 */
function wpsc_init() {
    // Initialize admin
    if ( is_admin() ) {
        new WPSC_Admin();
    }

    // Initialize public-facing features
    new WPSC_Public();

    // Initialize REST API handler
    new WPSC_Chat_Handler();
}
add_action( 'plugins_loaded', 'wpsc_init' );

/**
 * Handle auto re-indexing cron event
 */
function wpsc_auto_index_content() {
    $indexer = new WPSC_Indexer();
    $indexer->index_all_content();
}
add_action( 'wpsc_auto_index_content', 'wpsc_auto_index_content' );
