<?php
/**
 * SEO content strategy registry.
 *
 * @package SmartyPress_AI_Engine
 * @since 1.0.0
 */

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

/**
 * Stores strategy instances by SEO test ID.
 */
class SmartyPress_AI_SEO_Content_Strategy_Registry {

	/**
	 * Registered strategies.
	 *
	 * @var SmartyPress_AI_SEO_Strategy_Interface[]
	 */
	private $strategies = array();

	/**
	 * Constructor.
	 */
	public function __construct() {
		$this->register( new SmartyPress_AI_SEO_Strategy_Keyword_Intro() );
		$this->register( new SmartyPress_AI_SEO_Strategy_Keyword_Content() );
		$this->register( new SmartyPress_AI_SEO_Strategy_TOC() );
		$this->register( new SmartyPress_AI_SEO_Strategy_Keyword_Subheading() );
		$this->register( new SmartyPress_AI_SEO_Strategy_Content_Length() );
		$this->register( new SmartyPress_AI_SEO_Strategy_Keyword_Density() );
		$this->register( new SmartyPress_AI_SEO_Strategy_Short_Paragraphs() );
		$this->register( new SmartyPress_AI_SEO_Strategy_Readability( 'sentenceLengthInText', 'sentence_length', __( 'Sentence length in text', 'smartypress-ai-engine' ) ) );
		$this->register( new SmartyPress_AI_SEO_Strategy_Readability( 'transitionWords', 'transition_words', __( 'Transition words', 'smartypress-ai-engine' ) ) );

		/**
		 * Filters SEO content strategies.
		 *
		 * @param SmartyPress_AI_SEO_Strategy_Interface[] $strategies Strategies keyed by test ID.
		 */
		$this->strategies = apply_filters( 'smartypress_ai_seo_content_strategies', $this->strategies );
	}

	/**
	 * Register a strategy.
	 *
	 * @param SmartyPress_AI_SEO_Strategy_Interface $strategy Strategy.
	 * @return void
	 */
	public function register( $strategy ) {
		if ( ! $strategy instanceof SmartyPress_AI_SEO_Strategy_Interface ) {
			return;
		}

		$this->strategies[ $strategy->get_test_id() ] = $strategy;
	}

	/**
	 * Get a strategy by test ID.
	 *
	 * @param string $test_id Test ID.
	 * @return SmartyPress_AI_SEO_Strategy_Interface|null
	 */
	public function get( $test_id ) {
		$test_id = preg_replace( '/[^A-Za-z0-9_-]/', '', (string) $test_id );

		return isset( $this->strategies[ $test_id ] ) ? $this->strategies[ $test_id ] : null;
	}

	/**
	 * Get all registered strategies.
	 *
	 * @return SmartyPress_AI_SEO_Strategy_Interface[]
	 */
	public function all() {
		return $this->strategies;
	}
}
