"""Shared HTTP client factory for connectors.

Connectors get their ``httpx.AsyncClient`` from here so tests can inject a
``MockTransport`` and exercise the real connector code without network access.
"""

from __future__ import annotations

from collections.abc import Callable

import httpx

_client_factory: Callable[[], httpx.AsyncClient] | None = None


def set_async_client_factory(factory: Callable[[], httpx.AsyncClient] | None) -> None:
    global _client_factory
    _client_factory = factory


def new_async_client() -> httpx.AsyncClient:
    if _client_factory is not None:
        return _client_factory()
    return httpx.AsyncClient(timeout=30.0, follow_redirects=True)
