"""
Startup report of which agents are actually usable on this deployment.

The platform starts happily with no downstream URLs configured, then fails one
agent at a time as each is first called. This logs the whole picture once, at
boot, so a misconfigured deployment is visible immediately.

Warnings only — a partly-configured deployment must still start and serve the
agents that *are* configured.
"""
import logging
import os

from enterprise_ai.agents.catalog import AGENT_ROUTES

logger = logging.getLogger(__name__)


def _configured(env_names) -> bool:
    return any((os.getenv(name) or "").strip() for name in env_names)


def check_agent_environment() -> dict:
    ready, defaulted, missing = [], [], []

    for route in AGENT_ROUTES:
        if not route.url_env or _configured(route.url_env):
            ready.append(route)
        elif route.optional_url:
            defaulted.append(route)
        else:
            missing.append(route)

    logger.info(
        "[env] %d/%d agents configured: %s",
        len(ready), len(AGENT_ROUTES),
        ", ".join(r.slug for r in ready) or "none",
    )

    for route in defaulted:
        logger.info(
            "[env] /%s using built-in default URL — set %s to override",
            route.slug, route.url_env[0],
        )

    for route in missing:
        logger.warning(
            "[env] /%s DISABLED — set %s (POST /%s returns 503 until then)",
            route.slug, " or ".join(route.url_env), route.slug,
        )

    return {
        "ready": [r.slug for r in ready],
        "defaulted": [r.slug for r in defaulted],
        "missing": [r.slug for r in missing],
    }
