<?php
declare(strict_types=1);

namespace Ekesto\CacheInvalidator\Core\Elementor;

/**
 * Predictable holder for the active Elementor integration provider.
 */
final class ElementorIntegrationRegistry
{
    /** @var ElementorIntegrationInterface|null */
    private static ?ElementorIntegrationInterface $provider = null;

    /**
     * Register the active Elementor integration provider.
     *
     * @param ElementorIntegrationInterface $provider Provider instance.
     * @return void
     */
    public static function setProvider(ElementorIntegrationInterface $provider): void
    {
        self::$provider = $provider;
    }

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

        return self::$provider;
    }

    /**
     * Reset the active provider to the default null provider.
     *
     * @return void
     */
    public static function reset(): void
    {
        self::$provider = null;
    }
}
