"""Helper functions for AsyncNamespaces data plane operations."""

from __future__ import annotations

from typing import Any

import orjson

from pinecone._internal.constants import DATA_PLANE_HEADERS


async def _make_data_plane_request(
    self: Any,
    method: str,
    path: str,
    *,
    body: dict[str, Any] | None = None,
    params: dict[str, Any] | None = None,
) -> bytes:
    """Make an async HTTP request to the data plane API."""
    url = f"{self._base_url}{path}"
    content = orjson.dumps(body) if body is not None else None

    if method == "GET":
        response = await self._http.get(url, headers=DATA_PLANE_HEADERS, params=params)
    elif method == "DELETE":
        response = await self._http.request(
            "DELETE", url, headers=DATA_PLANE_HEADERS, params=params
        )
    else:
        response = await self._http.post(
            url, headers=DATA_PLANE_HEADERS, content=content, params=params
        )

    return response.content  # type: ignore[no-any-return]
