<?php
/**
 * Main plugin bootstrap.
 *
 * @package CatalogPilot\AiStudio
 */

namespace CatalogPilot\AiStudio;

defined( 'ABSPATH' ) || exit;

require_once CPAIS_PATH . 'includes/class-pro.php';
require_once CPAIS_PATH . 'includes/class-gateway.php';
require_once CPAIS_PATH . 'includes/class-settings.php';
require_once CPAIS_PATH . 'includes/class-cache.php';
require_once CPAIS_PATH . 'includes/class-seo.php';
require_once CPAIS_PATH . 'includes/class-media.php';
require_once CPAIS_PATH . 'includes/providers/class-provider.php';
require_once CPAIS_PATH . 'includes/providers/class-openai.php';
require_once CPAIS_PATH . 'includes/providers/class-anthropic.php';
require_once CPAIS_PATH . 'includes/providers/class-openai-compat.php';
require_once CPAIS_PATH . 'includes/providers/class-gemini.php';
require_once CPAIS_PATH . 'includes/providers/class-image-provider.php';
require_once CPAIS_PATH . 'includes/providers/class-image-openai.php';
require_once CPAIS_PATH . 'includes/providers/class-image-replicate.php';
require_once CPAIS_PATH . 'includes/providers/class-image-gemini.php';
require_once CPAIS_PATH . 'includes/providers/class-image-stability.php';
require_once CPAIS_PATH . 'includes/class-generator.php';
require_once CPAIS_PATH . 'includes/class-bulk.php';
require_once CPAIS_PATH . 'includes/class-scanner.php';
require_once CPAIS_PATH . 'includes/class-faq.php';
require_once CPAIS_PATH . 'includes/class-product-schema.php';
require_once CPAIS_PATH . 'includes/class-review.php';
require_once CPAIS_PATH . 'includes/class-rest-api.php';
require_once CPAIS_PATH . 'admin/class-admin.php';
require_once CPAIS_PATH . 'admin/class-ai-extras-metabox.php';

final class Plugin {

	private static $instance = null;

	public static function instance() {
		if ( null === self::$instance ) {
			self::$instance = new self();
		}
		return self::$instance;
	}

	private function __construct() {
		if ( ! $this->is_woocommerce_active() ) {
			add_action( 'admin_notices', array( $this, 'woocommerce_missing_notice' ) );
			return;
		}


		Settings::instance();
		REST_API::instance();
		Bulk::instance();
		FAQ::instance();
		Product_Schema::instance();
		Review::instance();

		if ( is_admin() ) {
			Admin::instance();
			AI_Extras_MetaBox::instance();
		}
	}

	private function is_woocommerce_active() {
		return class_exists( 'WooCommerce' );
	}

	public function woocommerce_missing_notice() {
		echo '<div class="notice notice-error"><p>';
		esc_html_e( 'CatalogPilot AI Studio for WooCommerce requires WooCommerce to be installed and active.', 'catalogpilot-ai-studio-for-woocommerce' );
		echo '</p></div>';
	}

	public static function activate() {
		add_option( 'cpais_version', CPAIS_VERSION );
	}

	public static function deactivate() {
		// Intentionally empty — options retained until uninstall.
	}
}
