47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
"""Small construction helper used by the application bootstrap layer."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import httpx
|
|
|
|
from .api_client import ApiClient
|
|
from .mock_repository import DemoDoctorRepository
|
|
from .repository import DoctorRepository, RemoteDoctorRepository
|
|
from .token_store import TokenStore
|
|
|
|
|
|
def build_repository(
|
|
*,
|
|
demo: bool,
|
|
base_url: str | None = None,
|
|
token_store: TokenStore | None = None,
|
|
client: ApiClient | None = None,
|
|
token: str = "",
|
|
timeout: float | httpx.Timeout = 30.0,
|
|
max_retries: int = 2,
|
|
verify: bool = True,
|
|
) -> DoctorRepository:
|
|
"""Build a demo or remote repository without depending on ``AppConfig``.
|
|
|
|
``client`` is primarily useful for tests or advanced bootstrap code. For
|
|
normal remote use, provide ``base_url`` and this factory creates the
|
|
correctly configured :class:`ApiClient`.
|
|
"""
|
|
|
|
if demo:
|
|
if client is not None:
|
|
raise ValueError("client cannot be supplied in demo mode")
|
|
return DemoDoctorRepository()
|
|
api_client = client
|
|
if api_client is None:
|
|
if base_url is None or not base_url.strip():
|
|
raise ValueError("base_url is required in remote mode")
|
|
api_client = ApiClient(
|
|
base_url,
|
|
token=token,
|
|
timeout=timeout,
|
|
max_retries=max_retries,
|
|
verify=verify,
|
|
)
|
|
return RemoteDoctorRepository(api_client, token_store)
|