"""Environment helper (D-108, REQ-159, REQ-164).

During the Nova rebrand transition window (P2–P4), `get_env` read
`NOVA_*` preferred with the legacy `ACDL_*` name as the fallback. **P5
(REQ-164) removed the fallback** — `get_env` now reads `NOVA_*` only.

`get_env(name, default=None)` resolves `NOVA_<name>`, then returns
`default` if unset. Direct-read paths that bypass this helper (the
`.env.secrets` shell export in `scripts/run_platform.sh` and the Python
parser in `core/regression_verify.py`) were updated to NOVA-only in P5
(the G-106 dual-read contract was retired with the fallback).
"""

from __future__ import annotations

import os
from typing import Optional

__all__ = ["get_env"]


def get_env(name: str, default: Optional[str] = None) -> Optional[str]:
    """Resolve a config value from the `NOVA_*` environment.

    `name` is the bare key WITHOUT the prefix (e.g. ``"AWS_ACCOUNT_ID"``).
    Returns ``NOVA_<name>`` if set and non-empty, else ``default``.
    """
    val = os.environ.get(f"NOVA_{name}")
    if val:
        return val
    return default