"""Douanier config — paths, dev token, version. Env-overridable, sane defaults.

Flat-module layout (run from this dir): the service imports `config` and
`engines.*` directly, matching the tide-table analyzers' sibling-import style.
"""
import os
from pathlib import Path

# ── identity ──────────────────────────────────────────────────────────────────
SERVICE = "douanier"                 # internal codename; the public sub-API is "audio".
VERSION = "v1"                       # the audio sub-API's own version (independent).

# api.nech.pl is a multi-API PLATFORM (SRE update 2026-06-25): Douanier is the
# `audio` sub-API, served publicly at /audio/v1/... The gateway strips that prefix
# and proxies to us at root (so internally routes are /healthz, /analyze/emotion…).
# root_path makes FastAPI advertise the public paths in /openapi.json + docs.
ROOT_PATH = os.environ.get("DOUANIER_ROOT_PATH", "/audio/v1")

# ── central auth (platform-owned) ────────────────────────────────────────────
# The platform does CENTRAL auth + metering: nginx `auth_request` validates the
# bearer at the edge and injects the caller identity as these headers. We bind
# loopback-only (reachable only via the gateway) and TRUST them — no token store
# of our own (supersedes #23/#24). See SRE.md.
TENANT_HEADER = os.environ.get("DOUANIER_TENANT_HEADER", "X-Tenant")
SCOPES_HEADER = os.environ.get("DOUANIER_SCOPES_HEADER", "X-Scopes")

# ── repo-relative paths ─────────────────────────────────────────────────────────
HERE = Path(__file__).resolve().parent          # armada/api
ARMADA = HERE.parent                             # armada
TIDE_TABLE = ARMADA / "tide-table"               # the ears engines live here
FOUNDRY = ARMADA.parent / "tools" / "foundry"    # the Foundry engines

# ── cache / data roots (transient — freebox is the SSOT later) ───────────────────
# Default to a local dir for dev; point CACHE_ROOT at the freebox mount in prod.
CACHE_ROOT = Path(os.environ.get("DOUANIER_CACHE", HERE / "_cache"))
DB_PATH = Path(os.environ.get("DOUANIER_DB", HERE / "_cache" / "douanier.db"))

# ── auth ─────────────────────────────────────────────────────────────────────
# WALKING-SKELETON stub (#36): one hardcoded bearer from the env, swapped for the
# SQLite token store in #23. No token set → the guarded routes return 503 (not
# wide open) so we never accidentally ship an unauthenticated endpoint.
DEV_TOKEN = os.environ.get("DOUANIER_DEV_TOKEN", "")

# ── limits ─────────────────────────────────────────────────────────────────────
MAX_UPLOAD_MB = int(os.environ.get("DOUANIER_MAX_UPLOAD_MB", "40"))

# ── engine selection ─────────────────────────────────────────────────────────
# "clap"  = CLAP/torch (rich, ~4 GB, needs the GPU/dev box) — default for local dev.
# "light" = librosa-heuristic V/A (no torch, fits the erable container) — set in prod.
EMOTION_ENGINE = os.environ.get("DOUANIER_EMOTION_ENGINE", "clap").lower()
