<?php

declare(strict_types=1);

namespace App\Services\Auth\Oauth;

class OauthRouter
{
    public function gateway(string $provider): OauthProviderInterface
    {
        $config = [
            'mock' => $this->isMockMode($provider),
        ];

        return match ($provider) {
            'kakao' => new KakaoProvider($config),
            'naver' => new NaverProvider($config),
            'google' => new GoogleProvider($config),
            'apple' => new AppleProvider($config),
            default => throw new \InvalidArgumentException("Unsupported OAuth provider: {$provider}"),
        };
    }

    public function isMockMode(string $provider): bool
    {
        $perProvider = env('OAUTH_'.strtoupper($provider).'_MOCK');
        if ($perProvider !== null) {
            return (bool) $perProvider;
        }
        return (bool) env('OAUTH_MOCK', '1');
    }
}
