from __future__ import annotations

from google import genai

from app.config import get_settings

_client: genai.Client | None = None


def init_vertex() -> None:
    global _client
    settings = get_settings()
    if not settings.gcp_project_id or settings.gcp_project_id == "your-gcp-project":
        raise RuntimeError("GCP_PROJECT_ID is not set.")
    _client = genai.Client(
        vertexai=True,
        project=settings.gcp_project_id,
        location=settings.gcp_location,
    )


def get_client() -> genai.Client:
    if _client is None:
        raise RuntimeError("Vertex AI is not initialized.")
    return _client
