from .model_metadata import create_model_metadata

# Adding a custom model: append a ``create_model_metadata(...)`` entry below (for
# chat models) or a name to ``OPENAI_EMBEDDING_MODEL_NAMES`` (for embeddings).
# Custom entries survive the models.dev catalog override
# (``apply_models_dev_overrides``) — any name models.dev doesn't cover is carried
# over rather than discarded. The ``openai_api_base`` / ``OPENAI_API_BASE``
# setting (for OpenAI-compatible servers) is configured separately per-component
# and is independent of this catalog. Embedding dropdowns have no free-text
# combobox, so a custom embedding must appear here to be selectable.

# Unified model metadata - single source of truth
OPENAI_MODELS_DETAILED = [
    # GPT-5.4 Series
    create_model_metadata(
        provider="OpenAI",
        name="gpt-5.4",
        icon="OpenAI",
        tool_calling=True,
        reasoning=True,
    ),
    create_model_metadata(
        provider="OpenAI",
        name="gpt-5.4-mini",
        icon="OpenAI",
        tool_calling=True,
        reasoning=True,
    ),
    create_model_metadata(
        provider="OpenAI",
        name="gpt-5.4-pro",
        icon="OpenAI",
        tool_calling=True,
        reasoning=True,
    ),
    # GPT-5.3 Series
    create_model_metadata(
        provider="OpenAI",
        name="gpt-5.3-codex",
        icon="OpenAI",
        tool_calling=True,
        reasoning=True,
    ),
    # GPT-5.2 and earlier
    create_model_metadata(
        provider="OpenAI",
        name="gpt-5.2",
        icon="OpenAI",
        tool_calling=True,
        reasoning=True,
    ),
    create_model_metadata(
        provider="OpenAI",
        name="gpt-5.1",
        icon="OpenAI",
        tool_calling=True,
        reasoning=True,
    ),
    create_model_metadata(
        provider="OpenAI",
        name="gpt-5",
        icon="OpenAI",
        tool_calling=True,
        reasoning=True,
    ),
    create_model_metadata(
        provider="OpenAI",
        name="gpt-5-mini",
        icon="OpenAI",
        tool_calling=True,
        reasoning=True,
    ),
    create_model_metadata(
        provider="OpenAI",
        name="gpt-5-nano",
        icon="OpenAI",
        tool_calling=True,
        reasoning=True,
    ),
    create_model_metadata(
        provider="OpenAI",
        name="gpt-5-chat-latest",
        icon="OpenAI",
        tool_calling=False,
        reasoning=True,
    ),
    # Regular OpenAI Models
    create_model_metadata(provider="OpenAI", name="gpt-4o-mini", icon="OpenAI", tool_calling=True),
    create_model_metadata(provider="OpenAI", name="gpt-4o", icon="OpenAI", tool_calling=True),
    create_model_metadata(provider="OpenAI", name="gpt-4.1", icon="OpenAI", tool_calling=True),
    create_model_metadata(provider="OpenAI", name="gpt-4.1-mini", icon="OpenAI", tool_calling=True),
    create_model_metadata(provider="OpenAI", name="gpt-4.1-nano", icon="OpenAI", tool_calling=True),
    create_model_metadata(
        provider="OpenAI", name="gpt-4.5-preview", icon="OpenAI", tool_calling=True, preview=True, deprecated=True
    ),
    create_model_metadata(provider="OpenAI", name="gpt-4-turbo", icon="OpenAI", tool_calling=True),
    create_model_metadata(
        provider="OpenAI", name="gpt-4-turbo-preview", icon="OpenAI", tool_calling=True, preview=True, deprecated=True
    ),
    create_model_metadata(provider="OpenAI", name="gpt-4", icon="OpenAI", tool_calling=True),
    create_model_metadata(provider="OpenAI", name="gpt-3.5-turbo", icon="OpenAI", tool_calling=True, deprecated=True),
    # Reasoning Models
    create_model_metadata(provider="OpenAI", name="o1", icon="OpenAI", reasoning=True),
    create_model_metadata(
        provider="OpenAI", name="o1-mini", icon="OpenAI", reasoning=True, not_supported=True, deprecated=True
    ),
    create_model_metadata(provider="OpenAI", name="o1-pro", icon="OpenAI", reasoning=True, not_supported=True),
    create_model_metadata(provider="OpenAI", name="o3-mini", icon="OpenAI", reasoning=True, not_supported=True),
    create_model_metadata(provider="OpenAI", name="o3", icon="OpenAI", reasoning=True, not_supported=True),
    create_model_metadata(provider="OpenAI", name="o3-pro", icon="OpenAI", reasoning=True, not_supported=True),
    create_model_metadata(provider="OpenAI", name="o4-mini", icon="OpenAI", reasoning=True, not_supported=True),
    # Search Models
    create_model_metadata(
        provider="OpenAI",
        name="gpt-4o-mini-search-preview",
        icon="OpenAI",
        tool_calling=True,
        search=True,
        preview=True,
    ),
    create_model_metadata(
        provider="OpenAI",
        name="gpt-4o-search-preview",
        icon="OpenAI",
        tool_calling=True,
        search=True,
        preview=True,
    ),
    # Not Supported Models
    create_model_metadata(
        provider="OpenAI", name="computer-use-preview", icon="OpenAI", not_supported=True, preview=True
    ),
    create_model_metadata(
        provider="OpenAI", name="gpt-4o-audio-preview", icon="OpenAI", not_supported=True, preview=True
    ),
    create_model_metadata(
        provider="OpenAI", name="gpt-4o-realtime-preview", icon="OpenAI", not_supported=True, preview=True
    ),
    create_model_metadata(
        provider="OpenAI", name="gpt-4o-mini-audio-preview", icon="OpenAI", not_supported=True, preview=True
    ),
    create_model_metadata(
        provider="OpenAI", name="gpt-4o-mini-realtime-preview", icon="OpenAI", not_supported=True, preview=True
    ),
]
OPENAI_CHAT_MODEL_NAMES = [
    metadata["name"]
    for metadata in OPENAI_MODELS_DETAILED
    if not metadata.get("not_supported", False)
    and not metadata.get("reasoning", False)
    and not metadata.get("search", False)
]

OPENAI_REASONING_MODEL_NAMES = [
    metadata["name"]
    for metadata in OPENAI_MODELS_DETAILED
    if metadata.get("reasoning", False) and not metadata.get("not_supported", False)
]

OPENAI_SEARCH_MODEL_NAMES = [
    metadata["name"]
    for metadata in OPENAI_MODELS_DETAILED
    if metadata.get("search", False) and not metadata.get("not_supported", False)
]

NOT_SUPPORTED_MODELS = [metadata["name"] for metadata in OPENAI_MODELS_DETAILED if metadata.get("not_supported", False)]

OPENAI_EMBEDDING_MODEL_NAMES = [
    "text-embedding-3-small",
    "text-embedding-3-large",
    "text-embedding-ada-002",
]

# Embedding models as detailed metadata
OPENAI_EMBEDDING_MODELS_DETAILED = [
    create_model_metadata(
        provider="OpenAI",
        name=name,
        icon="OpenAI",
        model_type="embeddings",
    )
    for name in OPENAI_EMBEDDING_MODEL_NAMES
]

# Backwards compatibility
MODEL_NAMES = OPENAI_CHAT_MODEL_NAMES
OPENAI_MODEL_NAMES = OPENAI_CHAT_MODEL_NAMES
