<?php
/**
 * HooksLoader class.
 *
 * Registers all admin-related hooks by resolving them from the DI container.
 *
 * @package Ilabs\Firevert\Core\Hooks
 */

declare( strict_types=1 );

namespace Ilabs\Firevert\Core\Hooks;

use Ilabs\Firevert\Core\Hooks\Admin\AdminCptHook;
use Ilabs\Firevert\Core\Hooks\Admin\AdminInitHook;
use Ilabs\Firevert\Core\Hooks\Admin\AdminMenuHook;
use Ilabs\Firevert\Core\Hooks\Admin\AdminNoticeHook;
use Ilabs\Firevert\Core\Hooks\Admin\PluginActionLinksHook;
use Ilabs\Firevert\Core\Hooks\Admin\ProductCacheInvalidationHook;
use Ilabs\Firevert\Core\Hooks\Admin\ProductCategoriesCacheInvalidationHook;
use Ilabs\Firevert\Core\ServiceContainer;

/**
 * Class HooksLoader
 *
 * Loads and registers all WordPress hooks for the plugin.
 */
final class HooksLoader {

	/**
	 * Dependency injection container.
	 *
	 * @var ServiceContainer
	 */
	protected ServiceContainer $container;

	/**
	 * Constructor.
	 *
	 * @param ServiceContainer $container Get from DI container.
	 */
	public function __construct( ServiceContainer $container ) {
		$this->container = $container;
	}

	/**
	 * Registers all hooks.
	 */
	public function register(): void {
		$this->register_admin();
	}

	/**
	 * Registers admin-specific hooks.
	 */
	private function register_admin(): void {
		$hooks = array(
			new AdminInitHook(),
			new AdminMenuHook( $this->container->get( 'settings_page_renderer' ) ),
			new AdminCptHook(),
			new AssetsHook( $this->container->get( 'asset_loader' ) ),
			new AdminNoticeHook(),
			new PluginActionLinksHook( 'firevert/firevert.php', 'firevert' ),
			new ProductCacheInvalidationHook(),
			new ProductCategoriesCacheInvalidationHook(),
		);

		foreach ( $hooks as $hook ) {
			if ( method_exists( $hook, 'register' ) ) {
				$hook->register();
			}
		}
	}
}
