<?php
/**
 * SEO Optimization Module Entry Point.
 *
 * @package SmartyPress_AI_Engine
 * @since 1.0.0
 */

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

if ( ! defined( 'SPAI_SO_PLUGIN_ACTIVE' ) ) {
	define( 'SPAI_SO_PLUGIN_VERSION', '1.0.0' );
	define( 'SPAI_SO_PLUGIN_ACTIVE', true );
	define( 'SPAI_SO_PLUGIN_DIR', dirname( __FILE__ ) );
	define( 'SPAI_SO_PLUGIN_URL', plugins_url( '', __FILE__ ) );

	require_once SPAI_SO_PLUGIN_DIR . '/contracts/class-seo-provider-integration.php';
	require_once SPAI_SO_PLUGIN_DIR . '/contracts/class-seo-strategy-interface.php';
	require_once SPAI_SO_PLUGIN_DIR . '/class-seo-provider-registry.php';
	require_once SPAI_SO_PLUGIN_DIR . '/providers/rank-math/class-rank-math-integration.php';
	require_once SPAI_SO_PLUGIN_DIR . '/providers/generic/class-generic-integration.php';
	require_once SPAI_SO_PLUGIN_DIR . '/strategies/class-seo-strategy-base.php';
	require_once SPAI_SO_PLUGIN_DIR . '/strategies/class-seo-strategy-keyword-intro.php';
	require_once SPAI_SO_PLUGIN_DIR . '/strategies/class-seo-strategy-keyword-content.php';
	require_once SPAI_SO_PLUGIN_DIR . '/strategies/class-seo-strategy-toc.php';
	require_once SPAI_SO_PLUGIN_DIR . '/strategies/class-seo-strategy-keyword-subheading.php';
	require_once SPAI_SO_PLUGIN_DIR . '/strategies/class-seo-strategy-keyword-density.php';
	require_once SPAI_SO_PLUGIN_DIR . '/strategies/class-seo-strategy-content-length.php';
	require_once SPAI_SO_PLUGIN_DIR . '/strategies/class-seo-strategy-short-paragraphs.php';
	require_once SPAI_SO_PLUGIN_DIR . '/strategies/class-seo-strategy-readability.php';
	require_once SPAI_SO_PLUGIN_DIR . '/class-seo-content-strategy-registry.php';
	require_once SPAI_SO_PLUGIN_DIR . '/class-seo-fix-prompt-builder.php';
	require_once SPAI_SO_PLUGIN_DIR . '/class-seo-controller-service-base.php';
	require_once SPAI_SO_PLUGIN_DIR . '/class-seo-context-service.php';
	require_once SPAI_SO_PLUGIN_DIR . '/class-seo-local-pre-checks.php';
	require_once SPAI_SO_PLUGIN_DIR . '/class-seo-ai-json-generator.php';
	require_once SPAI_SO_PLUGIN_DIR . '/class-seo-analysis-service.php';
	require_once SPAI_SO_PLUGIN_DIR . '/class-seo-meta-step-service.php';
	require_once SPAI_SO_PLUGIN_DIR . '/class-seo-content-strategy-runner.php';
	require_once SPAI_SO_PLUGIN_DIR . '/class-seo-result-normalizer.php';
	require_once SPAI_SO_PLUGIN_DIR . '/class-seo-fix-pipeline-runner.php';
	require_once SPAI_SO_PLUGIN_DIR . '/class-seo-optimization-controller.php';
	require_once SPAI_SO_PLUGIN_DIR . '/class-seo-optimization-module.php';

	add_filter(
		'smartypress_ai_module_seo_optimization_metadata',
		function( $metadata ) {
			return array(
				'name'        => __( 'SEO Optimization', 'smartypress-ai-engine' ),
				'description' => __( 'Fix SEO recommendations in supported SEO plugins using AI.', 'smartypress-ai-engine' ),
				'icon'        => SMARTYPRESS_AI_PLUGIN_URL . 'assets/images/seo-optimization-icon.svg',
				'type'        => 'internal',
				'build'       => 'free',
			);
		}
	);

	if ( class_exists( 'SmartyPress_AI_SEO_Optimization_Module' ) ) {
		$smartypress_ai_providers = SmartyPress_AI_Providers::get_all();
		$smartypress_ai_settings  = get_option( 'smartypress_ai_settings', array() );

		new SmartyPress_AI_SEO_Optimization_Module( $smartypress_ai_providers, $smartypress_ai_settings );
	}
}
