<?php

namespace MDCE;

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

final class Plugin {

	private static ?self $instance = null;

	private function __construct() {}

	public static function boot(): void {
		self::get_instance()->init();
	}

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

	private function init(): void {
		$this->load_dependencies();
		$this->register_hooks();
	}

	private function load_dependencies(): void {
		require_once MDCE_PLUGIN_DIR . 'includes/class-pro-bridge.php';
		require_once MDCE_PLUGIN_DIR . 'includes/class-settings.php';
		require_once MDCE_PLUGIN_DIR . 'includes/class-post-types.php';
		require_once MDCE_PLUGIN_DIR . 'includes/class-scheduler.php';
		require_once MDCE_PLUGIN_DIR . 'includes/class-expiration-processor.php';
		require_once MDCE_PLUGIN_DIR . 'includes/class-meta-box.php';
		require_once MDCE_PLUGIN_DIR . 'includes/class-sitemap-exclusion.php';
		require_once MDCE_PLUGIN_DIR . 'includes/class-search-exclusion.php';

		if ( is_admin() ) {
			require_once MDCE_PLUGIN_DIR . 'admin/class-admin.php';
			require_once MDCE_PLUGIN_DIR . 'admin/class-columns.php';
		}
	}

	private function register_hooks(): void {
		$settings   = new Settings();
		$post_types = new PostTypes( $settings );
		$scheduler  = new Scheduler();
		$processor  = new ExpirationProcessor();
		$meta_box   = new MetaBox( $post_types );

		$meta_box->register();
		$scheduler->register();
		$processor->register();
		( new SitemapExclusion() )->register();
		( new SearchExclusion() )->register();

		if ( is_admin() ) {
			( new Admin\Admin( $settings, $post_types ) )->register();
			( new Admin\Columns( $post_types ) )->register();
		}
	}

	public static function is_pro(): bool {
		return ProBridge::is_active();
	}

	public static function can_use_premium_code(): bool {
		return ProBridge::is_active() && ProBridge::is_licensed();
	}
}
