"""Gateway view for listing models."""

from __future__ import annotations

from typing import Optional

from ember.types import ModelSummary


def list_models(
    provider: Optional[str] = None, status: Optional[str] = None
) -> dict[str, ModelSummary]:
    """Return a JSON-serializable catalog of models for the gateway.

    Args:
        provider: Optional provider filter (e.g., "openai", "anthropic", "google").
        status: Optional status filter (e.g., "stable", "preview").

    Returns:
        Mapping of model_id to metadata dict {provider, description, context_window, status}.
    """
    from ember.models.catalog import MODEL_CATALOG

    out: dict[str, ModelSummary] = {}
    for model_id, info in MODEL_CATALOG.items():
        if provider and info.provider != provider:
            continue
        if status and info.status != status:
            continue
        out[model_id] = {
            "provider": info.provider,
            "description": info.description,
            "context_window": info.context_window,
            "status": info.status,
        }
    return out
