<?php
declare(strict_types=1);

namespace Ekesto\CacheInvalidator\Core\WooCommerce;

/**
 * Predictable holder for the active WooCommerce integration provider.
 */
final class WooCommerceIntegrationRegistry
{
    /** @var WooCommerceIntegrationInterface|null */
    private static ?WooCommerceIntegrationInterface $provider = null;

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

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

        return self::$provider;
    }

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