<?php
declare(strict_types=1);

namespace Ekesto\CacheWarmup\Multilingual;

use Ekesto\CacheWarmup\Multilingual\Adapters\PolylangAdapter;
use Ekesto\CacheWarmup\Multilingual\Adapters\TranslatePressAdapter;
use Ekesto\CacheWarmup\Multilingual\Adapters\WpmlAdapter;

/**
 * Multilingual adapter factory.
 */
final class AdapterFactory
{
    /**
     * Create the first active multilingual adapter.
     *
     * @return LanguageAdapterInterface|null Active adapter or null when none are active.
     */
    public static function create(): ?LanguageAdapterInterface
    {
        $adapters = [
            // Deterministic order keeps current WPML-first behavior.
            new WpmlAdapter(),
            new PolylangAdapter(),
            new TranslatePressAdapter(),
        ];

        foreach ($adapters as $adapter) {
            if ($adapter->isActive()) {
                return $adapter;
            }
        }

        return null;
    }
}
