"""Delete method for async_collections namespace."""

from __future__ import annotations

from typing import Any

from pinecone._internal.logging import get_logger
from pinecone._internal.validation import require_non_empty


logger = get_logger(__name__)


async def delete(self: Any, name: str, *, timeout: int | None = None) -> None:
    """Delete a collection.

    Args:
        name: Collection name to delete.
        timeout: Optional timeout in seconds for the API request.

    Raises:
        ValueError: If name is empty or timeout is not positive.
        NotFoundError: If collection not found.
        APIError: If deletion fails.

    Example:
        >>> await pc.collections.delete("my-backup")
    """
    # Validate inputs
    require_non_empty("name", name)
    if timeout is not None and timeout <= 0:
        raise ValueError("timeout must be a positive integer")

    logger.info(
        "Deleting collection",
        collection_name=name,
        timeout=timeout,
    )

    try:
        # Make HTTP request
        await self._http.delete(
            f"{self._base_url}/collections/{name}",
            headers=self._headers,
            timeout=timeout,
        )

        logger.info("Collection deletion initiated", collection_name=name)
        # Note: API returns 202 (async deletion), no response body

    except Exception:
        logger.exception("Failed to delete collection", collection_name=name)
        raise
