"""Delete namespace method for AsyncNamespaces."""

from __future__ import annotations

from typing import Any

import msgspec

from pinecone._internal.validation import require_non_empty
from pinecone.models.namespaces.delete import DeleteNamespaceResponse


_DECODER = msgspec.json.Decoder(DeleteNamespaceResponse)


async def delete(self: Any, *, name: str) -> DeleteNamespaceResponse:
    """Delete a namespace from the index.

    Args:
        name (str): The name of the namespace to delete.

    Returns:
        DeleteNamespaceResponse (empty on success).

    Raises:
        ValueError: If required parameters are empty.
        PineconeApiException: If the API request fails.

    Examples:
        >>> await index.namespaces.delete(name="my-namespace")
    """
    require_non_empty("name", name)
    data = await self._make_data_plane_request("DELETE", f"/namespaces/{name}")
    return _DECODER.decode(data)
