<?php
/**
 * Main plugin singleton.
 *
 * @package WPLens
 */

namespace WPLens;

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

final class Plugin {

	private static $instance = null;

	public static function instance(): Plugin {
		if ( null === self::$instance ) {
			self::$instance = new self();
		}
		return self::$instance;
	}

	private function __construct() {}

	public function boot(): void {
		// Pillar 1 — crawler detection runs on every front-end request.
		( new \WPLens\Crawler\Detector() )->register();

		// Cron schedules.
		\WPLens\Cron::register();

		// Admin UI.
		if ( is_admin() ) {
			( new \WPLens\Admin\Menu() )->register();
			( new \WPLens\Admin\Settings() )->register();
			( new \WPLens\Admin\Ajax() )->register();
			( new \WPLens\Admin\Welcome() )->register();
			( new \WPLens\Admin\PostsColumn() )->register();
			( new \WPLens\Admin\PluginLinks() )->register();
		}

		// Schema engine — emits JSON-LD on every front-end page.
		( new \WPLens\Schema\SchemaEngine() )->register();

		// REST API.
		( new \WPLens\Rest\Routes() )->register();
	}
}
