<?php
declare(strict_types=1);

namespace Ekesto\CacheInvalidator\Core\Relationships;

use Ekesto\CacheInvalidator\Core\Contracts\RelationshipProviderInterface;

/**
 * Lite-safe holder for the active relationship propagation provider.
 *
 * Defaults to {@see NullRelationshipProvider}. The premium build swaps in a real
 * provider via {@see self::setProvider()} from a strippable Pro registrar. This
 * holder never references the premium namespace.
 */
final class RelationshipProviderRegistry
{
    /** @var RelationshipProviderInterface|null */
    private static ?RelationshipProviderInterface $provider = null;

    /**
     * Register the active relationship propagation provider.
     *
     * @param RelationshipProviderInterface $provider
     * @return void
     */
    public static function setProvider(RelationshipProviderInterface $provider): void
    {
        self::$provider = $provider;
    }

    /**
     * Return the active provider, falling back to the Lite-safe no-op default.
     *
     * @return RelationshipProviderInterface
     */
    public static function current(): RelationshipProviderInterface
    {
        if (self::$provider === null) {
            self::$provider = new NullRelationshipProvider();
        }

        return self::$provider;
    }
}
