<?php

/**
 * Plugin Name: Content Craft AI: SEO & AI Article Generator
 * Description: Content Craft AI is a powerful WordPress plugin that generate human-like SEO articles that bypass AI detectors like GPTZero and Originality.ai using our advanced WordPress plugin.
 * Version: 4.1.4
 * Plugin URI: https://fluxlogic.us
 * Author: FluxLogic
 * License: GPLv2 or later
 * License URI: http://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: content-craft-ai
 */

// If this file is called directly, abort.
if (!defined('ABSPATH')) {
    exit;
}

// Define plugin constants
define('CONTENT_CRAFT_AI_PLUGIN_PATH', plugin_dir_path(__FILE__));
define('CONTENT_CRAFT_AI_PLUGIN_URL', plugin_dir_url(__FILE__));
define('CONTENT_CRAFT_AI_VERSION', '4.1.4');
define('CONTENT_CRAFT_AI_EXTERNAL_API', 'https://content-craft-api-railway-production.up.railway.app/api/v1');
// define('CONTENT_CRAFT_AI_EXTERNAL_API', 'http://localhost:3000/api/v1');

// Composer autoloader
if (file_exists(CONTENT_CRAFT_AI_PLUGIN_PATH . 'vendor/autoload.php')) {
    require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'vendor/autoload.php';
}

// Include database files
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/database/DatabaseSetup.php';
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/database/ArticleGenerationManager.php';
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/database/ScheduledArticleManager.php';
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/database/InternalLinksManager.php';
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/database/ArticleStatusManager.php';
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/database/TutorialManager.php';
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/database/VerificationManager.php';

// Include controller files
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/controllers/article-generator/BaseController.php';
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/controllers/article-generator/ScheduledArticleController.php';
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/controllers/notifications/notifications-controller.php';

// Include core files
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/includes/auth-check.php';
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/includes/assets.php';
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/includes/menu.php';
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/includes/internal-links.php';

// Include hooks
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/hooks/internal-links.php';

// Include helpers
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/helpers/redirect.php';

// Include API files
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/api/auth/index.php';
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/api/settings/index.php';
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/api/features/index.php';
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/api/dashboard/index.php';
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/api/article-generator/index.php';
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/api/title-article/index.php';
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/api/article-status/index.php';
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/api/notifications/index.php';
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/api/tutorial/index.php';
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/api/verification/index.php';

// Include cron files
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/cron/scheduled-articles.php';
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/cron/article-statuses.php';
require_once CONTENT_CRAFT_AI_PLUGIN_PATH . 'app/cron/activation.php';

// Initialize the plugin
add_action('init', 'content_craft_ai_init');

/**
 * Initialize database when plugin is activated
 */
function content_craft_ai_on_activation()
{
    // Set up database tables
    ContentCraftAI_DatabaseSetup::init_tables();

    // Initialize tutorial tracker
    ContentCraftAI_TutorialManager::init();

    // Refresh internal links
    if (class_exists('ContentCraftAI_InternalLinksManager')) {
        $internal_links_manager = ContentCraftAI_InternalLinksManager::get_instance();
        $internal_links_manager->refresh_internal_links();
    }
}

// Register activation function
register_activation_hook(__FILE__, 'content_craft_ai_on_activation');
