"""Shared runtime state: live-price cache and the effective (live/manual/catalog) provider list.""" from __future__ import annotations import copy import logging from app import live, manual from app.data.providers import CATALOG_DATE, PROVIDERS log = logging.getLogger("coremarket") live_cache: dict = {} def effective_providers() -> list[dict]: out = [] for p in PROVIDERS: if p.get("manual_defaults"): out.append(manual.apply(p)) continue p2 = copy.copy(p) lc = live_cache.get(p["id"]) if lc and lc.get("plans"): p2["plans"] = lc["plans"] p2["price_source"] = f"live API {lc['fetched_at']}" else: p2["price_source"] = f"catalog {CATALOG_DATE}" out.append(p2) return out async def refresh_live() -> dict: await live.refresh(live_cache) log.info("live pricing: %s", live_cache.get("_status")) return live_cache.get("_status", {})