"""Adapter for describe_index operation (2026-01.alpha API)."""

from __future__ import annotations

from typing import Any

import orjson

from msgspec import json as msgspec_json

from pinecone.models.indexes import IndexModel


def from_response(response_dict: dict[str, Any]) -> IndexModel:
    """Parse API response JSON to IndexModel.

    Uses msgspec for fast deserialization with automatic type validation.

    Args:
        response_dict: Dictionary from response.json()

    Returns:
        IndexModel instance

    Raises:
        msgspec.ValidationError: If response doesn't match IndexModel schema

    Example:
        >>> response = requests.get(...).json()
        >>> index = from_response(response)
        >>> print(f"{index.name}: {len(index.schema.fields)} fields")
    """
    decoder = msgspec_json.Decoder(IndexModel)
    return decoder.decode(orjson.dumps(response_dict))


__all__ = ["from_response"]
