<?php

namespace GriffinForms\Frontend\Html\Security\Captcha;

use GriffinForms\Traits\Singleton;

/**
 * Factory/manager for CAPTCHA adapters.
 */
class Manager
{
    use Singleton;

    protected $map = [
        'recaptcha'            => '\\GriffinForms\\Frontend\\Html\\Security\\Captcha\\Recaptcha',
        'cloudflare_turnstile' => '\\GriffinForms\\Frontend\\Html\\Security\\Captcha\\Turnstile',
        'hcaptcha'             => '\\GriffinForms\\Frontend\\Html\\Security\\Captcha\\Hcaptcha',
    ];

    public function create(string $provider_id, array $options, int $form_id): ?Format
    {
        if (!isset($this->map[$provider_id])) {
            return null;
        }

        $class = $this->map[$provider_id];
        if (!class_exists($class)) {
            return null;
        }

        return new $class($options, $form_id);
    }
}
