<?php

namespace DariusMure\Captcha\Services;

use DariusMure\Captcha\Services\Providers\CaptchaProviderInterface;
use DariusMure\Captcha\Services\Providers\HCaptchaProvider;
use DariusMure\Captcha\Services\Providers\ReCaptchaV2Provider;
use DariusMure\Captcha\Services\Providers\ReCaptchaV2InvisibleProvider;
use DariusMure\Captcha\Services\Providers\ReCaptchaV3Provider;
use DariusMure\Captcha\Services\Providers\TurnstileProvider;
use DariusMure\Captcha\Services\Providers\TrustIPProvider;

class CaptchaFactory
{
    /**
     * Create a CAPTCHA provider instance
     *
     * @param string $provider
     * @param array $config
     * @return CaptchaProviderInterface
     * @throws \InvalidArgumentException
     */
    public static function make(string $provider, array $config): CaptchaProviderInterface
    {
        return match ($provider) {
            'hcaptcha' => new HCaptchaProvider($config),
            'recaptcha_v2' => new ReCaptchaV2Provider($config),
            'recaptcha_v2_invisible' => new ReCaptchaV2InvisibleProvider($config),
            'recaptcha_v3' => new ReCaptchaV3Provider($config),
            'turnstile' => new TurnstileProvider($config),
            'trustip' => new TrustIPProvider($config),
            default => throw new \InvalidArgumentException("Unsupported CAPTCHA provider: {$provider}"),
        };
    }

    /**
     * Get all available providers
     *
     * @return array
     */
    public static function getAvailableProviders(): array
    {
        return [
            'hcaptcha' => 'hCaptcha',
            'recaptcha_v2' => 'reCAPTCHA v2',
            'recaptcha_v2_invisible' => 'reCAPTCHA v2 Invisible',
            'recaptcha_v3' => 'reCAPTCHA v3',
            'turnstile' => 'Cloudflare Turnstile',
            'trustip' => 'TrustIP',
        ];
    }
}
