<?php
/**
 * Gutenberg blocks bootstrap.
 *
 * @package SEOvaultSEO\Blocks
 */

namespace SEOvaultSEO\Blocks;

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

/**
 * Registers SEOvault blocks.
 */
class Bootstrap {

	/**
	 * Whether init has run.
	 *
	 * @var bool
	 */
	private static $initialized = false;

	/**
	 * Hook block registration.
	 *
	 * @return void
	 */
	public static function init() {
		if ( self::$initialized ) {
			return;
		}
		self::$initialized = true;

		add_action( 'init', array( __CLASS__, 'register_blocks' ), 20 );

		// Explicit legacy FAQ conversion tool (never trusts attributes for emission).
		LegacyFaqRichBlockEndpoints::init();

		// Rank Math / Yoast FAQ & HowTo → SEOvault block conversion (opt-in via AJAX/REST).
		ThirdPartyBlockEndpoints::init();

		// Disable inline FAQPage JSON-LD inside unconverted legacy rich wrappers.
		add_filter( 'the_content', array( LegacyFaqRichBlockConverter::class, 'filter_disable_legacy_inline_jsonld' ), 12 );
	}

	/**
	 * Register all SEOvault blocks.
	 *
	 * @return void
	 */
	public static function register_blocks() {
		FaqBlock::register();
		QuickAnswerBlock::register();
		HowToBlock::register();
	}
}
