"""Adapter for list_indexes 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 IndexList


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

    Uses msgspec for fast deserialization with automatic type validation.

    Args:
        response_dict: Dictionary from response.json()

    Returns:
        IndexList instance containing list of IndexModel objects

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

    Example:
        >>> response = requests.get(...).json()
        >>> index_list = from_response(response)
        >>> for index in index_list.indexes:
        ...     print(f"{index.name}: {index.status.state}")
    """
    decoder = msgspec_json.Decoder(IndexList)
    return decoder.decode(orjson.dumps(response_dict))


__all__ = ["from_response"]
