"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from .basesdk import BaseSDK
from .sdkconfiguration import SDKConfiguration
from lambdadb import errors, models, utils
from lambdadb._hooks import HookContext
from lambdadb.docs import Docs
from lambdadb.types import OptionalNullable, UNSET
from lambdadb.utils import get_security_from_env
from typing import Any, Dict, List, Mapping, Optional, Union


class Collections(BaseSDK):
    docs: Docs

    def __init__(self, sdk_config: SDKConfiguration) -> None:
        BaseSDK.__init__(self, sdk_config)
        self.sdk_configuration = sdk_config
        self._init_sdks()

    def _init_sdks(self):
        self.docs = Docs(self.sdk_configuration)

    def list(
        self,
        *,
        project_name: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.ListCollectionsResponse:
        r"""List all collections in an existing project.

        :param project_name: Project name.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.ListCollectionsRequest(
            project_name=project_name,
        )

        req = self._build_request(
            method="GET",
            path="/projects/{projectName}/collections",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "5XX"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="listCollections",
                oauth2_scopes=[],
                security_source=get_security_from_env(
                    self.sdk_configuration.security, models.Security
                ),
            ),
            request=req,
            error_status_codes=["401", "404", "429", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return utils.unmarshal_json_response(
                models.ListCollectionsResponse, http_res
            )
        if utils.match_response(http_res, "401", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.UnauthenticatedErrorData, http_res
            )
            raise errors.UnauthenticatedError(response_data, http_res)
        if utils.match_response(http_res, "404", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.ResourceNotFoundErrorData, http_res
            )
            raise errors.ResourceNotFoundError(response_data, http_res)
        if utils.match_response(http_res, "429", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.TooManyRequestsErrorData, http_res
            )
            raise errors.TooManyRequestsError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.InternalServerErrorData, http_res
            )
            raise errors.InternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.APIError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.APIError("API error occurred", http_res, http_res_text)

        raise errors.APIError("Unexpected response received", http_res)

    async def list_async(
        self,
        *,
        project_name: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.ListCollectionsResponse:
        r"""List all collections in an existing project.

        :param project_name: Project name.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.ListCollectionsRequest(
            project_name=project_name,
        )

        req = self._build_request_async(
            method="GET",
            path="/projects/{projectName}/collections",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "5XX"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="listCollections",
                oauth2_scopes=[],
                security_source=get_security_from_env(
                    self.sdk_configuration.security, models.Security
                ),
            ),
            request=req,
            error_status_codes=["401", "404", "429", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return utils.unmarshal_json_response(
                models.ListCollectionsResponse, http_res
            )
        if utils.match_response(http_res, "401", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.UnauthenticatedErrorData, http_res
            )
            raise errors.UnauthenticatedError(response_data, http_res)
        if utils.match_response(http_res, "404", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.ResourceNotFoundErrorData, http_res
            )
            raise errors.ResourceNotFoundError(response_data, http_res)
        if utils.match_response(http_res, "429", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.TooManyRequestsErrorData, http_res
            )
            raise errors.TooManyRequestsError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.InternalServerErrorData, http_res
            )
            raise errors.InternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.APIError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.APIError("API error occurred", http_res, http_res_text)

        raise errors.APIError("Unexpected response received", http_res)

    def create(
        self,
        *,
        project_name: str,
        collection_name: str,
        index_configs: Optional[
            Union[
                Dict[str, models.IndexConfigsUnion],
                Dict[str, models.IndexConfigsUnionTypedDict],
            ]
        ] = None,
        source_project_name: Optional[str] = None,
        source_collection_name: Optional[str] = None,
        source_datetime: Optional[str] = None,
        source_project_api_key: Optional[str] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.CreateCollectionResponse:
        r"""Create a collection.

        :param project_name: Project name.
        :param collection_name: Collection name must be unique within a project and the supported maximum length is 52.
        :param index_configs:
        :param source_project_name:
        :param source_collection_name:
        :param source_datetime:
        :param source_project_api_key:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.CreateCollectionRequest(
            project_name=project_name,
            request_body=models.CreateCollectionRequestBody(
                collection_name=collection_name,
                index_configs=utils.get_pydantic_model(
                    index_configs, Optional[Dict[str, models.IndexConfigsUnion]]
                ),
                source_project_name=source_project_name,
                source_collection_name=source_collection_name,
                source_datetime=source_datetime,
                source_project_api_key=source_project_api_key,
            ),
        )

        req = self._build_request(
            method="POST",
            path="/projects/{projectName}/collections",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request.request_body,
                False,
                False,
                "json",
                models.CreateCollectionRequestBody,
            ),
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "5XX"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="createCollection",
                oauth2_scopes=[],
                security_source=get_security_from_env(
                    self.sdk_configuration.security, models.Security
                ),
            ),
            request=req,
            error_status_codes=["400", "401", "409", "429", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "202", "application/json"):
            return utils.unmarshal_json_response(
                models.CreateCollectionResponse, http_res
            )
        if utils.match_response(http_res, "400", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.BadRequestErrorData, http_res
            )
            raise errors.BadRequestError(response_data, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.UnauthenticatedErrorData, http_res
            )
            raise errors.UnauthenticatedError(response_data, http_res)
        if utils.match_response(http_res, "409", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.ResourceAlreadyExistsErrorData, http_res
            )
            raise errors.ResourceAlreadyExistsError(response_data, http_res)
        if utils.match_response(http_res, "429", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.TooManyRequestsErrorData, http_res
            )
            raise errors.TooManyRequestsError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.InternalServerErrorData, http_res
            )
            raise errors.InternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.APIError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.APIError("API error occurred", http_res, http_res_text)

        raise errors.APIError("Unexpected response received", http_res)

    async def create_async(
        self,
        *,
        project_name: str,
        collection_name: str,
        index_configs: Optional[
            Union[
                Dict[str, models.IndexConfigsUnion],
                Dict[str, models.IndexConfigsUnionTypedDict],
            ]
        ] = None,
        source_project_name: Optional[str] = None,
        source_collection_name: Optional[str] = None,
        source_datetime: Optional[str] = None,
        source_project_api_key: Optional[str] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.CreateCollectionResponse:
        r"""Create a collection.

        :param project_name: Project name.
        :param collection_name: Collection name must be unique within a project and the supported maximum length is 52.
        :param index_configs:
        :param source_project_name:
        :param source_collection_name:
        :param source_datetime:
        :param source_project_api_key:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.CreateCollectionRequest(
            project_name=project_name,
            request_body=models.CreateCollectionRequestBody(
                collection_name=collection_name,
                index_configs=utils.get_pydantic_model(
                    index_configs, Optional[Dict[str, models.IndexConfigsUnion]]
                ),
                source_project_name=source_project_name,
                source_collection_name=source_collection_name,
                source_datetime=source_datetime,
                source_project_api_key=source_project_api_key,
            ),
        )

        req = self._build_request_async(
            method="POST",
            path="/projects/{projectName}/collections",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request.request_body,
                False,
                False,
                "json",
                models.CreateCollectionRequestBody,
            ),
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "5XX"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="createCollection",
                oauth2_scopes=[],
                security_source=get_security_from_env(
                    self.sdk_configuration.security, models.Security
                ),
            ),
            request=req,
            error_status_codes=["400", "401", "409", "429", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "202", "application/json"):
            return utils.unmarshal_json_response(
                models.CreateCollectionResponse, http_res
            )
        if utils.match_response(http_res, "400", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.BadRequestErrorData, http_res
            )
            raise errors.BadRequestError(response_data, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.UnauthenticatedErrorData, http_res
            )
            raise errors.UnauthenticatedError(response_data, http_res)
        if utils.match_response(http_res, "409", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.ResourceAlreadyExistsErrorData, http_res
            )
            raise errors.ResourceAlreadyExistsError(response_data, http_res)
        if utils.match_response(http_res, "429", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.TooManyRequestsErrorData, http_res
            )
            raise errors.TooManyRequestsError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.InternalServerErrorData, http_res
            )
            raise errors.InternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.APIError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.APIError("API error occurred", http_res, http_res_text)

        raise errors.APIError("Unexpected response received", http_res)

    def delete(
        self,
        *,
        project_name: str,
        collection_name: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.MessageResponse:
        r"""Delete an existing collection.

        :param project_name: Project name.
        :param collection_name: Collection name.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.DeleteCollectionRequest(
            project_name=project_name,
            collection_name=collection_name,
        )

        req = self._build_request(
            method="DELETE",
            path="/projects/{projectName}/collections/{collectionName}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "5XX"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="deleteCollection",
                oauth2_scopes=[],
                security_source=get_security_from_env(
                    self.sdk_configuration.security, models.Security
                ),
            ),
            request=req,
            error_status_codes=["401", "404", "429", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "202", "application/json"):
            return utils.unmarshal_json_response(models.MessageResponse, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.UnauthenticatedErrorData, http_res
            )
            raise errors.UnauthenticatedError(response_data, http_res)
        if utils.match_response(http_res, "404", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.ResourceNotFoundErrorData, http_res
            )
            raise errors.ResourceNotFoundError(response_data, http_res)
        if utils.match_response(http_res, "429", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.TooManyRequestsErrorData, http_res
            )
            raise errors.TooManyRequestsError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.InternalServerErrorData, http_res
            )
            raise errors.InternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.APIError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.APIError("API error occurred", http_res, http_res_text)

        raise errors.APIError("Unexpected response received", http_res)

    async def delete_async(
        self,
        *,
        project_name: str,
        collection_name: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.MessageResponse:
        r"""Delete an existing collection.

        :param project_name: Project name.
        :param collection_name: Collection name.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.DeleteCollectionRequest(
            project_name=project_name,
            collection_name=collection_name,
        )

        req = self._build_request_async(
            method="DELETE",
            path="/projects/{projectName}/collections/{collectionName}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "5XX"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="deleteCollection",
                oauth2_scopes=[],
                security_source=get_security_from_env(
                    self.sdk_configuration.security, models.Security
                ),
            ),
            request=req,
            error_status_codes=["401", "404", "429", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "202", "application/json"):
            return utils.unmarshal_json_response(models.MessageResponse, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.UnauthenticatedErrorData, http_res
            )
            raise errors.UnauthenticatedError(response_data, http_res)
        if utils.match_response(http_res, "404", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.ResourceNotFoundErrorData, http_res
            )
            raise errors.ResourceNotFoundError(response_data, http_res)
        if utils.match_response(http_res, "429", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.TooManyRequestsErrorData, http_res
            )
            raise errors.TooManyRequestsError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.InternalServerErrorData, http_res
            )
            raise errors.InternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.APIError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.APIError("API error occurred", http_res, http_res_text)

        raise errors.APIError("Unexpected response received", http_res)

    def get(
        self,
        *,
        project_name: str,
        collection_name: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.GetCollectionResponse:
        r"""Get metadata of an existing collection.

        :param project_name: Project name.
        :param collection_name: Collection name.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.GetCollectionRequest(
            project_name=project_name,
            collection_name=collection_name,
        )

        req = self._build_request(
            method="GET",
            path="/projects/{projectName}/collections/{collectionName}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "5XX"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="getCollection",
                oauth2_scopes=[],
                security_source=get_security_from_env(
                    self.sdk_configuration.security, models.Security
                ),
            ),
            request=req,
            error_status_codes=["401", "404", "429", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return utils.unmarshal_json_response(models.GetCollectionResponse, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.UnauthenticatedErrorData, http_res
            )
            raise errors.UnauthenticatedError(response_data, http_res)
        if utils.match_response(http_res, "404", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.ResourceNotFoundErrorData, http_res
            )
            raise errors.ResourceNotFoundError(response_data, http_res)
        if utils.match_response(http_res, "429", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.TooManyRequestsErrorData, http_res
            )
            raise errors.TooManyRequestsError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.InternalServerErrorData, http_res
            )
            raise errors.InternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.APIError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.APIError("API error occurred", http_res, http_res_text)

        raise errors.APIError("Unexpected response received", http_res)

    async def get_async(
        self,
        *,
        project_name: str,
        collection_name: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.GetCollectionResponse:
        r"""Get metadata of an existing collection.

        :param project_name: Project name.
        :param collection_name: Collection name.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.GetCollectionRequest(
            project_name=project_name,
            collection_name=collection_name,
        )

        req = self._build_request_async(
            method="GET",
            path="/projects/{projectName}/collections/{collectionName}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "5XX"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="getCollection",
                oauth2_scopes=[],
                security_source=get_security_from_env(
                    self.sdk_configuration.security, models.Security
                ),
            ),
            request=req,
            error_status_codes=["401", "404", "429", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return utils.unmarshal_json_response(models.GetCollectionResponse, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.UnauthenticatedErrorData, http_res
            )
            raise errors.UnauthenticatedError(response_data, http_res)
        if utils.match_response(http_res, "404", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.ResourceNotFoundErrorData, http_res
            )
            raise errors.ResourceNotFoundError(response_data, http_res)
        if utils.match_response(http_res, "429", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.TooManyRequestsErrorData, http_res
            )
            raise errors.TooManyRequestsError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.InternalServerErrorData, http_res
            )
            raise errors.InternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.APIError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.APIError("API error occurred", http_res, http_res_text)

        raise errors.APIError("Unexpected response received", http_res)

    def update(
        self,
        *,
        project_name: str,
        collection_name: str,
        index_configs: Union[
            Dict[str, models.IndexConfigsUnion],
            Dict[str, models.IndexConfigsUnionTypedDict],
        ],
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.UpdateCollectionResponse:
        r"""Configure a collection.

        :param project_name: Project name.
        :param collection_name: Collection name.
        :param index_configs:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.UpdateCollectionRequest(
            project_name=project_name,
            collection_name=collection_name,
            request_body=models.UpdateCollectionRequestBody(
                index_configs=utils.get_pydantic_model(
                    index_configs, Dict[str, models.IndexConfigsUnion]
                ),
            ),
        )

        req = self._build_request(
            method="PATCH",
            path="/projects/{projectName}/collections/{collectionName}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request.request_body,
                False,
                False,
                "json",
                models.UpdateCollectionRequestBody,
            ),
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "5XX"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="updateCollection",
                oauth2_scopes=[],
                security_source=get_security_from_env(
                    self.sdk_configuration.security, models.Security
                ),
            ),
            request=req,
            error_status_codes=["400", "401", "404", "429", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return utils.unmarshal_json_response(
                models.UpdateCollectionResponse, http_res
            )
        if utils.match_response(http_res, "400", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.BadRequestErrorData, http_res
            )
            raise errors.BadRequestError(response_data, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.UnauthenticatedErrorData, http_res
            )
            raise errors.UnauthenticatedError(response_data, http_res)
        if utils.match_response(http_res, "404", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.ResourceNotFoundErrorData, http_res
            )
            raise errors.ResourceNotFoundError(response_data, http_res)
        if utils.match_response(http_res, "429", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.TooManyRequestsErrorData, http_res
            )
            raise errors.TooManyRequestsError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.InternalServerErrorData, http_res
            )
            raise errors.InternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.APIError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.APIError("API error occurred", http_res, http_res_text)

        raise errors.APIError("Unexpected response received", http_res)

    async def update_async(
        self,
        *,
        project_name: str,
        collection_name: str,
        index_configs: Union[
            Dict[str, models.IndexConfigsUnion],
            Dict[str, models.IndexConfigsUnionTypedDict],
        ],
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.UpdateCollectionResponse:
        r"""Configure a collection.

        :param project_name: Project name.
        :param collection_name: Collection name.
        :param index_configs:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.UpdateCollectionRequest(
            project_name=project_name,
            collection_name=collection_name,
            request_body=models.UpdateCollectionRequestBody(
                index_configs=utils.get_pydantic_model(
                    index_configs, Dict[str, models.IndexConfigsUnion]
                ),
            ),
        )

        req = self._build_request_async(
            method="PATCH",
            path="/projects/{projectName}/collections/{collectionName}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request.request_body,
                False,
                False,
                "json",
                models.UpdateCollectionRequestBody,
            ),
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "5XX"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="updateCollection",
                oauth2_scopes=[],
                security_source=get_security_from_env(
                    self.sdk_configuration.security, models.Security
                ),
            ),
            request=req,
            error_status_codes=["400", "401", "404", "429", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return utils.unmarshal_json_response(
                models.UpdateCollectionResponse, http_res
            )
        if utils.match_response(http_res, "400", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.BadRequestErrorData, http_res
            )
            raise errors.BadRequestError(response_data, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.UnauthenticatedErrorData, http_res
            )
            raise errors.UnauthenticatedError(response_data, http_res)
        if utils.match_response(http_res, "404", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.ResourceNotFoundErrorData, http_res
            )
            raise errors.ResourceNotFoundError(response_data, http_res)
        if utils.match_response(http_res, "429", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.TooManyRequestsErrorData, http_res
            )
            raise errors.TooManyRequestsError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.InternalServerErrorData, http_res
            )
            raise errors.InternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.APIError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.APIError("API error occurred", http_res, http_res_text)

        raise errors.APIError("Unexpected response received", http_res)

    def query(
        self,
        *,
        project_name: str,
        collection_name: str,
        size: int,
        query: Optional[Dict[str, Any]] = None,
        consistent_read: Optional[bool] = False,
        include_vectors: Optional[bool] = False,
        sort: Optional[List[Dict[str, Any]]] = None,
        fields: Optional[List[str]] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.QueryCollectionResponse:
        r"""Search a collection with a query and return the most similar documents.

        :param project_name: Project name.
        :param collection_name: Collection name.
        :param size: Number of documents to return. Note that the maximum number of documents is 100.
        :param query: Query object.
        :param consistent_read: If your application requires a strongly consistent read, set consistentRead to true. Although a strongly consistent read might take more time than an eventually consistent read, it always returns the last updated value.
        :param include_vectors: If your application need to include vector values in the response, set includeVectors to true.
        :param sort: List of field name, sort direction pairs.
        :param fields: List of field name to include in results
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.QueryCollectionRequest(
            project_name=project_name,
            collection_name=collection_name,
            request_body=models.QueryCollectionRequestBody(
                size=size,
                query=query,
                consistent_read=consistent_read,
                include_vectors=include_vectors,
                sort=sort,
                fields=fields,
            ),
        )

        req = self._build_request(
            method="POST",
            path="/projects/{projectName}/collections/{collectionName}/query",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request.request_body,
                False,
                False,
                "json",
                models.QueryCollectionRequestBody,
            ),
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "5XX"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="queryCollection",
                oauth2_scopes=[],
                security_source=get_security_from_env(
                    self.sdk_configuration.security, models.Security
                ),
            ),
            request=req,
            error_status_codes=["400", "401", "404", "429", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return utils.unmarshal_json_response(
                models.QueryCollectionResponse, http_res
            )
        if utils.match_response(http_res, "400", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.BadRequestErrorData, http_res
            )
            raise errors.BadRequestError(response_data, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.UnauthenticatedErrorData, http_res
            )
            raise errors.UnauthenticatedError(response_data, http_res)
        if utils.match_response(http_res, "404", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.ResourceNotFoundErrorData, http_res
            )
            raise errors.ResourceNotFoundError(response_data, http_res)
        if utils.match_response(http_res, "429", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.TooManyRequestsErrorData, http_res
            )
            raise errors.TooManyRequestsError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.InternalServerErrorData, http_res
            )
            raise errors.InternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.APIError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.APIError("API error occurred", http_res, http_res_text)

        raise errors.APIError("Unexpected response received", http_res)

    async def query_async(
        self,
        *,
        project_name: str,
        collection_name: str,
        size: int,
        query: Optional[Dict[str, Any]] = None,
        consistent_read: Optional[bool] = False,
        include_vectors: Optional[bool] = False,
        sort: Optional[List[Dict[str, Any]]] = None,
        fields: Optional[List[str]] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.QueryCollectionResponse:
        r"""Search a collection with a query and return the most similar documents.

        :param project_name: Project name.
        :param collection_name: Collection name.
        :param size: Number of documents to return. Note that the maximum number of documents is 100.
        :param query: Query object.
        :param consistent_read: If your application requires a strongly consistent read, set consistentRead to true. Although a strongly consistent read might take more time than an eventually consistent read, it always returns the last updated value.
        :param include_vectors: If your application need to include vector values in the response, set includeVectors to true.
        :param sort: List of field name, sort direction pairs.
        :param fields: List of field name to include in results
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.QueryCollectionRequest(
            project_name=project_name,
            collection_name=collection_name,
            request_body=models.QueryCollectionRequestBody(
                size=size,
                query=query,
                consistent_read=consistent_read,
                include_vectors=include_vectors,
                sort=sort,
                fields=fields,
            ),
        )

        req = self._build_request_async(
            method="POST",
            path="/projects/{projectName}/collections/{collectionName}/query",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request.request_body,
                False,
                False,
                "json",
                models.QueryCollectionRequestBody,
            ),
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "5XX"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="queryCollection",
                oauth2_scopes=[],
                security_source=get_security_from_env(
                    self.sdk_configuration.security, models.Security
                ),
            ),
            request=req,
            error_status_codes=["400", "401", "404", "429", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return utils.unmarshal_json_response(
                models.QueryCollectionResponse, http_res
            )
        if utils.match_response(http_res, "400", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.BadRequestErrorData, http_res
            )
            raise errors.BadRequestError(response_data, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.UnauthenticatedErrorData, http_res
            )
            raise errors.UnauthenticatedError(response_data, http_res)
        if utils.match_response(http_res, "404", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.ResourceNotFoundErrorData, http_res
            )
            raise errors.ResourceNotFoundError(response_data, http_res)
        if utils.match_response(http_res, "429", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.TooManyRequestsErrorData, http_res
            )
            raise errors.TooManyRequestsError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = utils.unmarshal_json_response(
                errors.InternalServerErrorData, http_res
            )
            raise errors.InternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.APIError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.APIError("API error occurred", http_res, http_res_text)

        raise errors.APIError("Unexpected response received", http_res)
