<?php

namespace Waypoint\Agent;

use Waypoint\Agent\Acf\Loader;
use Waypoint\Agent\Admin\Dashboard;
use Waypoint\Agent\Admin\Flush_Everything;
use Waypoint\Agent\Admin\Key_Notice;
use Waypoint\Agent\Admin\Login_Logo;
use Waypoint\Agent\Admin\Settings;
use Waypoint\Agent\Admin\Settings_Page;
use Waypoint\Agent\Auth\Role_Manager;
use Waypoint\Agent\Base\Thing;
use Waypoint\Agent\Cli\Cache_Flush;
use Waypoint\Agent\Cli\Rotate_Key;
use Waypoint\Agent\Cli\Sync_Trusted_Admins;
use Waypoint\Agent\Cli\Waypoint_Admin;
use Waypoint\Agent\Compat\Rank_Math_Pro_Update_Guard;
use Waypoint\Agent\Compat\Wpo_Bypass;
use Waypoint\Agent\Integrations\Rank_Math;
use Waypoint\Agent\Integrations\Rank_Math_Disable_Content_Ai;
use Waypoint\Agent\Integrations\Rank_Math_Og_Fallback;
use Waypoint\Agent\Monitor\Registration;
use Waypoint\Agent\Rest\Router;
use Waypoint\Agent\Setup\Default_Content;
use Waypoint\Agent\Setup\Disable_Admin_Email_Check;
use Waypoint\Agent\Setup\Disable_Comments;
use Waypoint\Agent\Setup\Override_Admin_Email;

class Plugin extends Thing {

	public function attach_hooks(): void {
		// Always-on: core plugin infrastructure.
		$things = [
			new Rank_Math_Pro_Update_Guard(),
			new Wpo_Bypass(),
			new Registration(),
			new Router(),
			new Loader(),
			new Role_Manager(),
			new Settings_Page(),
			new Key_Notice(),
			new Login_Logo(),
		];

		// Optional: gated by settings (default all on).
		if ( Settings::get( 'dashboard_widget' ) ) {
			$things[] = new Dashboard();
		}
		if ( Settings::get( 'disable_admin_email_check' ) ) {
			$things[] = new Disable_Admin_Email_Check();
		}
		if ( Settings::get( 'disable_comments' ) ) {
			$things[] = new Disable_Comments();
		}
		if ( Settings::get( 'default_content_cleanup' ) ) {
			$things[] = new Default_Content();
		}
		if ( Settings::get( 'rank_math' ) ) {
			$things[] = new Rank_Math();
		}
		if ( Settings::get( 'rank_math_og_fallback' ) ) {
			$things[] = new Rank_Math_Og_Fallback();
		}
		if ( Settings::get( 'rank_math_disable_content_ai' ) ) {
			$things[] = new Rank_Math_Disable_Content_Ai();
		}
		if ( Settings::get( 'flush_everything' ) ) {
			$things[] = new Flush_Everything();
		}
		if( Settings::get( 'admin_email_override' ) ) {
			$things[] = new Override_Admin_Email();
		}

		if ( defined( 'WP_CLI' ) && WP_CLI ) {
			$things[] = new Rotate_Key();
			$things[] = new Waypoint_Admin();
			$things[] = new Cache_Flush();
			$things[] = new Sync_Trusted_Admins();
		}

		foreach ( $things as $thing ) {
			$thing->attach_hooks();
		}
	}
}
