<?php
/**
 * SEO metadata adapter registry.
 *
 * @package SmartyPress_AI_Engine
 */

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

/**
 * Provides SEO metadata adapters for core and third-party integrations.
 */
class SmartyPress_AI_Content_Generator_SEO_Metadata_Adapter_Registry {

	/**
	 * Registered adapters.
	 *
	 * @var SmartyPress_AI_Content_Generator_SEO_Metadata_Adapter_Interface[]
	 */
	private $adapters;

	/**
	 * Constructor.
	 *
	 * @param array $adapters Adapter instances.
	 */
	public function __construct( array $adapters = array() ) {
		$this->adapters = empty( $adapters ) ? $this->get_default_adapters() : $adapters;
	}

	/**
	 * Get active adapters.
	 *
	 * @param array $metadata Neutral metadata package.
	 * @return SmartyPress_AI_Content_Generator_SEO_Metadata_Adapter_Interface[]
	 */
	public function get_adapters( array $metadata = array() ) {
		$adapters = apply_filters( 'smartypress_ai_seo_metadata_adapters', $this->adapters, $metadata );
		$adapters = is_array( $adapters ) ? $adapters : array();

		return array_values(
			array_filter(
				$adapters,
				function ( $adapter ) {
					return $adapter instanceof SmartyPress_AI_Content_Generator_SEO_Metadata_Adapter_Interface && $adapter->is_available();
				}
			)
		);
	}

	/**
	 * Default adapters.
	 *
	 * @return array
	 */
	private function get_default_adapters() {
		return array(
			new SmartyPress_AI_Content_Generator_WordPress_Slug_SEO_Metadata_Adapter(),
			new SmartyPress_AI_Content_Generator_Rank_Math_SEO_Metadata_Adapter(),
			new SmartyPress_AI_Content_Generator_Yoast_SEO_Metadata_Adapter(),
			new SmartyPress_AI_Content_Generator_AIOSEO_Metadata_Adapter(),
		);
	}
}
