"""Async fetch method for AsyncIndex."""

from __future__ import annotations

from typing import Any

import msgspec

from pinecone.models.index.fetch import FetchResponse


_DECODER = msgspec.json.Decoder(FetchResponse)


async def fetch(
    self: Any,
    ids: list[str],
    *,
    namespace: str = "",
) -> FetchResponse:
    """Fetch vectors by ID.

    Args:
        ids: List of vector IDs to fetch.
        namespace: Namespace to fetch from.

    Returns:
        FetchResponse with the fetched vectors.

    Example:
        >>> response = await index.fetch(ids=["vec1", "vec2"])
    """
    params: dict[str, Any] = {"ids": ids}
    if namespace:
        params["namespace"] = namespace

    data = await self._make_data_plane_request("GET", "/vectors/fetch", params=params)
    return _DECODER.decode(data)
