<?php
/**
 * SettingsRegistry class.
 *
 * Central registry for Firevert settings groups.
 * Stores metadata for system-level and module-level settings definitions.
 * Does not perform any rendering or registration in WordPress — only stores structured data.
 *
 * @package Ilabs\Firevert\Core\Settings\Registry
 */

declare( strict_types=1 );

namespace Ilabs\Firevert\Core\Settings\Registry;

/**
 * Registry for Firevert plugin and module settings.
 *
 * This class only stores data — it does not register WordPress hooks or output HTML.
 */
class SettingsRegistry {

	/**
	 * All registered groups.
	 *
	 * @var array<string, array>
	 */
	private array $groups = array();

	/**
	 * Registered module groups.
	 *
	 * @var array<string, array>
	 */
	private array $module_groups = array();

	/**
	 * Registered general groups.
	 *
	 * @var array<string, array>
	 */
	private array $general_groups = array();

	/**
	 * Returns static tabs for the top-level settings navigation.
	 *
	 * @return array<string, string> Tab slug => tab label.
	 */
	public function get_static_tabs(): array {
		return array(
			'general'               => __( 'Global settings', 'firevert' ),
			'modules'               => __( 'Modules', 'firevert' ),
			'support'               => __( 'Support', 'firevert' ),
			'partners_and_services' => __( 'Partners and services', 'firevert' ),
		);
	}

	/**
	 * Registers a new group of settings.
	 *
	 * @param string $slug Unique group slug.
	 * @param array  $definition Group definition (title, description, fields, is_module).
	 *
	 * @return void
	 */
	public function register_group( string $slug, array $definition ): void {
		$this->groups[ $slug ] = $definition;

		if ( $definition['is_module'] ?? false ) {
			$this->module_groups[ $slug ] = $definition;
		} else {
			$this->general_groups[ $slug ] = $definition;
		}
	}

	/**
	 * Returns all registered groups.
	 *
	 * @return array<string, array> Group slug => definition.
	 */
	public function get_groups(): array {
		return $this->groups;
	}

	/**
	 * Returns all registered module groups.
	 *
	 * @return array<string, array> Module group definitions.
	 */
	public function get_module_groups(): array {
		return $this->module_groups;
	}

	/**
	 * Returns all registered general groups.
	 *
	 * @return array<string, array> General group definitions.
	 */
	public function get_general_groups(): array {
		return $this->general_groups;
	}

	/**
	 * Returns the definition of a single group.
	 *
	 * @param string $slug Group slug.
	 *
	 * @return array|null Group definition or null if not found.
	 */
	public function get_group( string $slug ): ?array {
		return $this->groups[ $slug ] ?? null;
	}

	/**
	 * Returns fields for a given group.
	 *
	 * @param string $slug Group slug.
	 *
	 * @return array<int, array> List of field definitions.
	 */
	public function get_fields( string $slug ): array {
		return $this->groups[ $slug ]['fields'] ?? array();
	}
}
