"""Project metadata read from ``pyproject.toml`` (single source of truth).

No duplication — callers import from here, never re-declare the metadata.
Uses ``Path(__file__)`` to locate ``pyproject.toml`` regardless of CWD.
"""

from __future__ import annotations

import tomllib
from dataclasses import dataclass
from pathlib import Path

_PYPROJECT = Path(__file__).resolve().parents[3] / "pyproject.toml"


@dataclass(frozen=True)
class ProjectMetadata:
    name: str
    version: str
    description: str


def load_metadata() -> ProjectMetadata:
    """Load metadata from ``pyproject.toml`` (single source of truth)."""
    with _PYPROJECT.open("rb") as f:
        data = tomllib.load(f)
    project = data.get("project", {})
    return ProjectMetadata(
        name=str(project.get("name", "")),
        version=str(project.get("version", "")),
        description=str(project.get("description", "")),
    )


metadata = load_metadata()