<?php
/**
 * ModuleRegistry — service locator for module instances.
 *
 * The Plugin loader instantiates this once and registers every module here.
 * Admin pages fetch modules by id to render status and shortcuts.
 *
 * @package Platform\Helm\Core
 */

declare( strict_types = 1 );

namespace Platform\Helm\Core;

use Platform\Helm\Contracts\ModuleInterface;

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

final class ModuleRegistry {

	/** @var array<string,ModuleInterface> */
	private array $modules = [];

	public function register( ModuleInterface $module ): void {
		$this->modules[ $module->id() ] = $module;
	}

	public function get( string $id ): ?ModuleInterface {
		return $this->modules[ $id ] ?? null;
	}

	/**
	 * @return array<string,ModuleInterface>
	 */
	public function all(): array {
		return $this->modules;
	}

	public function has( string $id ): bool {
		return isset( $this->modules[ $id ] );
	}
}
