<?php
/**
 * Content Generator Module Entry Point
 *
 * @package SmartyPress_AI_Engine
 * @since 1.0.0
 */

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

if ( ! defined( 'SPAI_CG_PLUGIN_ACTIVE' ) ) {
	define( 'SPAI_CG_PLUGIN_VERSION', '1.0.0' );
	define( 'SPAI_CG_PLUGIN_ACTIVE', true );
	define( 'SPAI_CG_PLUGIN_DIR', dirname( __FILE__ ) );
	define( 'SPAI_CG_PLUGIN_URL', plugins_url( '', __FILE__ ) );

	// Load service classes.
	require_once( SPAI_CG_PLUGIN_DIR . '/services/class-plan-parser.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/services/class-plan-normalizer.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/services/class-plan-summary-builder.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/services/class-draft-parser.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/services/class-markdown-block-converter.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/services/class-article-block-renderer.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/services/class-seo-generation-metadata-service.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/services/interface-seo-metadata-adapter.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/services/class-wordpress-slug-seo-metadata-adapter.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/services/class-rank-math-seo-metadata-adapter.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/services/class-yoast-seo-metadata-adapter.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/services/class-aioseo-metadata-adapter.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/services/class-seo-metadata-adapter-registry.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/services/class-seo-plugin-metadata-writer.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/services/class-seo-optimization-service.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/services/class-post-persistence-service.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/services/class-generation-language-service.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/services/class-generated-title-validator.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/services/class-seo-content-optimization-service.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/services/class-generation-step-service.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/services/class-generation-cost-estimator.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/services/class-bulk-prompt-service.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/services/class-bulk-job-repository.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/extensions/interface-post-type-extension.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/extensions/class-post-type-extension-registry.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/extensions/class-woocommerce-product-extension.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/services/class-bulk-item-context-service.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/services/class-bulk-legacy-generation-pipeline.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/services/class-legacy-post-generation-service.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/services/class-plan-generation-service.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/services/class-plan-draft-generation-service.php' );

	// Load generator classes
	require_once( SPAI_CG_PLUGIN_DIR . '/generators/class-abstract-post-generator.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/generators/class-single-post-generator.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/generators/class-bulk-post-generator.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/controllers/class-bulk-legacy-job-controller.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/controllers/class-bulk-plan-controller.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/routes/class-single-generation-routes.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/routes/class-bulk-legacy-routes.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/routes/class-bulk-plan-routes.php' );
	
	// Load integration classes
	require_once( SPAI_CG_PLUGIN_DIR . '/class-gutenberg-integration.php' );
	require_once( SPAI_CG_PLUGIN_DIR . '/class-classic-editor-integration.php' );
	
	// Load module class
	require_once( SPAI_CG_PLUGIN_DIR . '/class-content-generator-module.php' );
	
	// Register module metadata (without init hook to work with REST API)
	add_filter( 'smartypress_ai_module_content_generator_metadata', function( $metadata ) {
		return array(
			'name'        => __( 'Content Generator', 'smartypress-ai-engine' ),
			'description' => __( 'Generate single posts and bulk content using AI. Includes Gutenberg Magic Wand integration.', 'smartypress-ai-engine' ),
			'icon'        => SMARTYPRESS_AI_PLUGIN_URL . 'assets/images/content-generator-icon.svg',
			'type'        => 'internal',
			'build'       => 'free',
		);
	} );

	// Initialize module only if class exists
	if ( class_exists( 'SmartyPress_AI_Content_Generator_Module' ) ) {
		$smartypress_ai_providers = SmartyPress_AI_Providers::get_all();
		$smartypress_ai_settings  = get_option( 'smartypress_ai_settings', array() );

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

