<?php


namespace Fliegerlogin\WpPublic;


use Fliegerlogin\Guard;
use Fliegerlogin\Options;

class WpPublic {

	/** @var Authentication */
	private $authentication;

	public function __construct() {
		$this->setupDependencies();
		$this->setupHooks();
	}

	private function setupDependencies(): void {
		$this->authentication = new Authentication();
	}

	private function setupHooks(): void {
		// General hardening applies regardless of the Vereinsflieger setup state.
		Guard::registerHardening();

		add_action('login_enqueue_scripts', [Authentication::class, 'registerLoginAssets']);

		if (Options::setupComplete()) {
			add_filter('authenticate', [$this->authentication, 'authenticationRequest'], 50, 3);
			add_action('lostpassword_post', [$this->authentication, 'lostPasswordRequest'], 10, 2);
			add_filter('allow_password_reset', [$this->authentication, 'allowPasswordReset'], 10, 2);
		}
	}

	private static $public = null;
	public static function init(): self {
		if (!self::$public) {
			self::$public = new self();
		}

		return self::$public;
	}

}