"""List vectors method for Index."""

from __future__ import annotations

from typing import Any

import msgspec

from pinecone.models.index.list_vectors import ListVectorsResponse


_DECODER = msgspec.json.Decoder(ListVectorsResponse)


def list(
    self: Any,
    *,
    prefix: str | None = None,
    limit: int | None = None,
    pagination_token: str | None = None,
    namespace: str = "",
) -> ListVectorsResponse:
    """List vector IDs in a namespace.

    Args:
        prefix: Filter to IDs starting with this prefix.
        limit: Maximum number of IDs to return.
        pagination_token: Token to resume from a previous call.
        namespace: Namespace to list from.

    Returns:
        ListVectorsResponse with vector IDs and pagination info.

    Example:
        >>> response = index.list(prefix="doc#", limit=100)
        >>> for item in response.vectors:
        ...     print(item.id)
    """
    params: dict[str, Any] = {}
    if prefix is not None:
        params["prefix"] = prefix
    if limit is not None:
        params["limit"] = limit
    if pagination_token is not None:
        params["paginationToken"] = pagination_token
    if namespace:
        params["namespace"] = namespace

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