<?php
/**
 * The container: boots every subsystem exactly once.
 *
 * @package SEO_Flight_Recorder
 */

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

/**
 * Class SFRec_Plugin
 */
class SFRec_Plugin {

	/**
	 * Singleton instance.
	 *
	 * @var SFRec_Plugin|null
	 */
	private static $instance = null;

	/**
	 * Admin controller (admin requests only).
	 *
	 * @var SFRec_Admin|null
	 */
	public $admin = null;

	/**
	 * Accessor.
	 *
	 * @return SFRec_Plugin
	 */
	public static function instance() {
		if ( null === self::$instance ) {
			self::$instance = new self();
			self::$instance->boot();
		}
		return self::$instance;
	}

	/**
	 * Boot.
	 */
	private function boot() {
		SFRec_Install::maybe_upgrade();
		SFRec_Events::init();
		SFRec_Scanner::init();
		SFRec_Site_Health::init();
		SFRec_Rest::init();

		if ( is_admin() ) {
			$this->admin = new SFRec_Admin();
			$this->admin->init();
			SFRec_Baseline::init();
		}

		if ( defined( 'WP_CLI' ) && WP_CLI ) {
			WP_CLI::add_command( 'seo-flight-recorder', 'SFRec_CLI' );
		}

		/**
		 * The Pro layer (loaded before the container on licensed premium
		 * builds) finishes its wiring on this hook.
		 */
		do_action( 'sfrec_loaded' );
	}
}
