<?php

namespace SugarCalendarBookings\Integrations;

/**
 * Integration registry.
 *
 * Central registry for all third-party integrations. Each integration registers
 * itself here during bootstrap. The Integrations settings tab uses this registry
 * to render sidebar navigation items and content panels.
 *
 * @since 1.4.0
 */
class IntegrationRegistry {

	/**
	 * Registered integrations.
	 *
	 * @since 1.4.0
	 *
	 * @var IntegrationInterface[]
	 */
	private array $integrations = [];

	/**
	 * Register an integration.
	 *
	 * @since 1.4.0
	 *
	 * @param IntegrationInterface $integration Integration instance.
	 */
	public function register( IntegrationInterface $integration ): void {

		$this->integrations[ $integration->get_slug() ] = $integration;
	}

	/**
	 * Get all registered integrations.
	 *
	 * @since 1.4.0
	 *
	 * @return IntegrationInterface[]
	 */
	public function get_all(): array {

		return $this->integrations;
	}

	/**
	 * Get an integration by slug.
	 *
	 * @since 1.4.0
	 *
	 * @param string $slug Integration slug.
	 *
	 * @return IntegrationInterface|null
	 */
	public function get_by_slug( string $slug ): ?IntegrationInterface {

		return $this->integrations[ $slug ] ?? null;
	}
}
