"""Delete method for Index."""

from __future__ import annotations

from typing import Any

import msgspec

from pinecone.models.index.delete import DeleteResponse


_DECODER = msgspec.json.Decoder(DeleteResponse)


def delete(
    self: Any,
    *,
    ids: list[str] | None = None,
    delete_all: bool = False,
    namespace: str = "",
    filter: dict[str, Any] | None = None,
) -> DeleteResponse:
    """Delete vectors.

    Args:
        ids: Vector IDs to delete.
        delete_all: Delete all vectors in the namespace.
        namespace: Target namespace.
        filter: Delete vectors matching this metadata filter.

    Returns:
        DeleteResponse (empty on success).

    Example:
        >>> index.delete(ids=["vec1", "vec2"])
        >>> index.delete(delete_all=True, namespace="test")
    """
    body: dict[str, Any] = {}
    if ids is not None:
        body["ids"] = ids
    if delete_all:
        body["deleteAll"] = True
    if namespace:
        body["namespace"] = namespace
    if filter is not None:
        body["filter"] = filter

    data = self._make_data_plane_request("POST", "/vectors/delete", body=body)
    return _DECODER.decode(data)
