"""Cancel bulk import method for BulkImports."""

from __future__ import annotations

from typing import Any

import msgspec

from pinecone._internal.validation import require_non_empty
from pinecone.models.bulk_imports.cancel import CancelImportResponse


_DECODER = msgspec.json.Decoder(CancelImportResponse)


def cancel(
    self: Any,
    *,
    id: str,
) -> CancelImportResponse:
    """Cancel a bulk import operation.

    Args:
        id (str): The import operation ID to cancel.

    Returns:
        CancelImportResponse (empty on success).

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

    Examples:
        >>> index.bulk_imports.cancel(id="import-123")
    """
    require_non_empty("id", id)

    data = self._make_data_plane_request("DELETE", f"/bulk/imports/{id}")
    return _DECODER.decode(data)
