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

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

if ( ! defined( 'SPAI_IG_PLUGIN_ACTIVE' ) ) {
	define( 'SPAI_IG_PLUGIN_VERSION', '1.0.0' );
	define( 'SPAI_IG_PLUGIN_ACTIVE', true );
	define( 'SPAI_IG_PLUGIN_DIR', dirname( __FILE__ ) );
	define( 'SPAI_IG_PLUGIN_URL', plugins_url( '', __FILE__ ) );
	
	// Load module classes
	if ( ! class_exists( 'SmartyPress_AI_Content_Generator_Generation_Language_Service' ) ) {
		require_once( dirname( SPAI_IG_PLUGIN_DIR ) . '/content-generator/services/class-generation-language-service.php' );
	}
	require_once( SPAI_IG_PLUGIN_DIR . '/class-image-generator.php' );
	require_once( SPAI_IG_PLUGIN_DIR . '/class-image-generator-module.php' );
	
	// Register module metadata (without init hook to work with REST API)
	add_filter( 'smartypress_ai_module_image_generator_metadata', function( $metadata ) {
		return array(
			'name'        => __( 'Image Generator', 'smartypress-ai-engine' ),
			'description' => __( 'Create images from text prompts. Saves to Media Library with auto-generated title, alt, and description. Regenerate any image with a correction prompt.', 'smartypress-ai-engine' ),
			'icon'        => SMARTYPRESS_AI_PLUGIN_URL . 'assets/images/image-generator-icon.svg',
			'type'        => 'internal',
			'build'       => 'free',
		);
	} );

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

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

