<?php
/**
 * Prompt Registry — collects ability IDs + builder class names for MCP prompts.
 *
 * Returns a mixed array of:
 * - Ability ID strings → auto-converted to prompts by McpComponentRegistry
 * - Builder class names → custom workflow prompts extending McpPromptBuilder (Pro only, via filter)
 *
 * @package AtlasAiDev\Awfah\Prompts
 */

namespace AtlasAiDev\Awfah\Prompts;

use AtlasAiDev\Awfah\Plugin;

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

class Prompt_Registry {

	/**
	 * Static cache (request-scoped).
	 *
	 * @var string[]|null
	 */
	private static ?array $cache = null;

	/**
	 * Get the full list of prompt identifiers for MCP registration.
	 *
	 * Returns a mixed array of:
	 * - Ability ID strings (for auto-prompts derived from input_schema)
	 * - Fully-qualified class names implementing McpPromptBuilderInterface (Pro only)
	 *
	 * @return string[]
	 */
	public static function get_prompt_identifiers(): array {
		if ( null !== self::$cache ) {
			return self::$cache;
		}

		$prompts  = [];
		$settings = Plugin::get_settings();

		// 1. All available abilities become auto-prompts.
		foreach ( Plugin::get_available_mcp_abilities() as $ability ) {
			$prompts[] = $ability['id'];
		}

		// 2. Custom workflow prompt builders (Pro feature — injected via filter).
		$builders = apply_filters( 'awfah_prompt_builder_classes', [], $settings );
		foreach ( $builders as $builder_class ) {
			$prompts[] = $builder_class;
		}

		self::$cache = $prompts;

		return self::$cache;
	}

	/**
	 * Clear the static cache.
	 */
	public static function clear_cache(): void {
		self::$cache = null;
	}
}
