# This file was auto-generated by Fern from our API Definition.

import typing
from json.decoder import JSONDecodeError

from ..core.api_error import ApiError
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.http_response import AsyncHttpResponse, HttpResponse
from ..core.jsonable_encoder import jsonable_encoder
from ..core.request_options import RequestOptions
from ..core.serialization import convert_and_respect_annotation_metadata
from ..core.unchecked_base_model import construct_type
from ..errors.unprocessable_entity_error import UnprocessableEntityError
from ..types.http_validation_error import HttpValidationError
from ..types.schema_response import SchemaResponse
from ..types.src_app_http_routes_collection_create_table_response import SrcAppHttpRoutesCollectionCreateTableResponse
from ..types.src_app_http_routes_collection_delete_table_response import SrcAppHttpRoutesCollectionDeleteTableResponse
from ..types.src_app_http_routes_collection_get_table_response import SrcAppHttpRoutesCollectionGetTableResponse
from ..types.src_app_http_routes_collection_get_tables_response import SrcAppHttpRoutesCollectionGetTablesResponse
from ..types.src_app_http_routes_collection_sync_table_response import SrcAppHttpRoutesCollectionSyncTableResponse
from ..types.src_app_http_routes_collection_update_table_response import SrcAppHttpRoutesCollectionUpdateTableResponse
from .types.table_config_input_schema_item import TableConfigInputSchemaItem
from .types.table_data_schema_item import TableDataSchemaItem

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class RawTablesClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._client_wrapper = client_wrapper

    def list(
        self, collection_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[SrcAppHttpRoutesCollectionGetTablesResponse]:
        """
        Parameters
        ----------
        collection_id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[SrcAppHttpRoutesCollectionGetTablesResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/collections/{jsonable_encoder(collection_id)}/tables",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SrcAppHttpRoutesCollectionGetTablesResponse,
                    construct_type(
                        type_=SrcAppHttpRoutesCollectionGetTablesResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def create(
        self,
        collection_id: str,
        *,
        table_display_name: typing.Optional[str] = OMIT,
        table_img_url: typing.Optional[str] = OMIT,
        table_description: typing.Optional[str] = OMIT,
        schema: typing.Optional[typing.Sequence[TableConfigInputSchemaItem]] = OMIT,
        icon_emoji: typing.Optional[str] = OMIT,
        icon_asset_url: typing.Optional[str] = OMIT,
        icon_fill: typing.Optional[str] = OMIT,
        singular_name: typing.Optional[str] = OMIT,
        plural_name: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[SrcAppHttpRoutesCollectionCreateTableResponse]:
        """
        Parameters
        ----------
        collection_id : str

        table_display_name : typing.Optional[str]

        table_img_url : typing.Optional[str]

        table_description : typing.Optional[str]

        schema : typing.Optional[typing.Sequence[TableConfigInputSchemaItem]]

        icon_emoji : typing.Optional[str]

        icon_asset_url : typing.Optional[str]

        icon_fill : typing.Optional[str]

        singular_name : typing.Optional[str]

        plural_name : typing.Optional[str]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[SrcAppHttpRoutesCollectionCreateTableResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/collections/{jsonable_encoder(collection_id)}/tables",
            method="POST",
            json={
                "table_display_name": table_display_name,
                "table_img_url": table_img_url,
                "table_description": table_description,
                "schema": convert_and_respect_annotation_metadata(
                    object_=schema, annotation=typing.Sequence[TableConfigInputSchemaItem], direction="write"
                ),
                "icon_emoji": icon_emoji,
                "icon_asset_url": icon_asset_url,
                "icon_fill": icon_fill,
                "singular_name": singular_name,
                "plural_name": plural_name,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SrcAppHttpRoutesCollectionCreateTableResponse,
                    construct_type(
                        type_=SrcAppHttpRoutesCollectionCreateTableResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def get(
        self, collection_id: str, table_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[SrcAppHttpRoutesCollectionGetTableResponse]:
        """
        Parameters
        ----------
        collection_id : str

        table_id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[SrcAppHttpRoutesCollectionGetTableResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/collections/{jsonable_encoder(collection_id)}/tables/{jsonable_encoder(table_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SrcAppHttpRoutesCollectionGetTableResponse,
                    construct_type(
                        type_=SrcAppHttpRoutesCollectionGetTableResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def update(
        self,
        collection_id: str,
        table_id: str,
        *,
        table_display_name: typing.Optional[str] = OMIT,
        table_img_url: typing.Optional[str] = OMIT,
        table_description: typing.Optional[str] = OMIT,
        schema: typing.Optional[typing.Sequence[TableDataSchemaItem]] = OMIT,
        icon_emoji: typing.Optional[str] = OMIT,
        icon_asset_url: typing.Optional[str] = OMIT,
        icon_fill: typing.Optional[str] = OMIT,
        singular_name: typing.Optional[str] = OMIT,
        plural_name: typing.Optional[str] = OMIT,
        index_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[SrcAppHttpRoutesCollectionUpdateTableResponse]:
        """
        Parameters
        ----------
        collection_id : str

        table_id : str

        table_display_name : typing.Optional[str]

        table_img_url : typing.Optional[str]

        table_description : typing.Optional[str]

        schema : typing.Optional[typing.Sequence[TableDataSchemaItem]]

        icon_emoji : typing.Optional[str]

        icon_asset_url : typing.Optional[str]

        icon_fill : typing.Optional[str]

        singular_name : typing.Optional[str]

        plural_name : typing.Optional[str]

        index_id : typing.Optional[str]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[SrcAppHttpRoutesCollectionUpdateTableResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/collections/{jsonable_encoder(collection_id)}/tables/{jsonable_encoder(table_id)}",
            method="PUT",
            json={
                "table_display_name": table_display_name,
                "table_img_url": table_img_url,
                "table_description": table_description,
                "schema": convert_and_respect_annotation_metadata(
                    object_=schema, annotation=typing.Sequence[TableDataSchemaItem], direction="write"
                ),
                "icon_emoji": icon_emoji,
                "icon_asset_url": icon_asset_url,
                "icon_fill": icon_fill,
                "singular_name": singular_name,
                "plural_name": plural_name,
                "index_id": index_id,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SrcAppHttpRoutesCollectionUpdateTableResponse,
                    construct_type(
                        type_=SrcAppHttpRoutesCollectionUpdateTableResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def delete(
        self, collection_id: str, table_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[SrcAppHttpRoutesCollectionDeleteTableResponse]:
        """
        Delete a table given a collection_id and table_id.

        Parameters
        ----------
        collection_id : str

        table_id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[SrcAppHttpRoutesCollectionDeleteTableResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/collections/{jsonable_encoder(collection_id)}/tables/{jsonable_encoder(table_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SrcAppHttpRoutesCollectionDeleteTableResponse,
                    construct_type(
                        type_=SrcAppHttpRoutesCollectionDeleteTableResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def get_schema(
        self, collection_id: str, table_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[SchemaResponse]:
        """
        Parameters
        ----------
        collection_id : str

        table_id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[SchemaResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/collections/{jsonable_encoder(collection_id)}/tables/{jsonable_encoder(table_id)}/schema",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SchemaResponse,
                    construct_type(
                        type_=SchemaResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def sync(
        self,
        collection_id: str,
        table_id: str,
        *,
        request: typing.Sequence[typing.Dict[str, typing.Optional[typing.Any]]],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[SrcAppHttpRoutesCollectionSyncTableResponse]:
        """
        Sync a table with a list of documents.

        Parameters
        ----------
        collection_id : str

        table_id : str

        request : typing.Sequence[typing.Dict[str, typing.Optional[typing.Any]]]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[SrcAppHttpRoutesCollectionSyncTableResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/collections/{jsonable_encoder(collection_id)}/tables/{jsonable_encoder(table_id)}/sync",
            method="POST",
            json=request,
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SrcAppHttpRoutesCollectionSyncTableResponse,
                    construct_type(
                        type_=SrcAppHttpRoutesCollectionSyncTableResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)


class AsyncRawTablesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def list(
        self, collection_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[SrcAppHttpRoutesCollectionGetTablesResponse]:
        """
        Parameters
        ----------
        collection_id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[SrcAppHttpRoutesCollectionGetTablesResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/collections/{jsonable_encoder(collection_id)}/tables",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SrcAppHttpRoutesCollectionGetTablesResponse,
                    construct_type(
                        type_=SrcAppHttpRoutesCollectionGetTablesResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def create(
        self,
        collection_id: str,
        *,
        table_display_name: typing.Optional[str] = OMIT,
        table_img_url: typing.Optional[str] = OMIT,
        table_description: typing.Optional[str] = OMIT,
        schema: typing.Optional[typing.Sequence[TableConfigInputSchemaItem]] = OMIT,
        icon_emoji: typing.Optional[str] = OMIT,
        icon_asset_url: typing.Optional[str] = OMIT,
        icon_fill: typing.Optional[str] = OMIT,
        singular_name: typing.Optional[str] = OMIT,
        plural_name: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[SrcAppHttpRoutesCollectionCreateTableResponse]:
        """
        Parameters
        ----------
        collection_id : str

        table_display_name : typing.Optional[str]

        table_img_url : typing.Optional[str]

        table_description : typing.Optional[str]

        schema : typing.Optional[typing.Sequence[TableConfigInputSchemaItem]]

        icon_emoji : typing.Optional[str]

        icon_asset_url : typing.Optional[str]

        icon_fill : typing.Optional[str]

        singular_name : typing.Optional[str]

        plural_name : typing.Optional[str]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[SrcAppHttpRoutesCollectionCreateTableResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/collections/{jsonable_encoder(collection_id)}/tables",
            method="POST",
            json={
                "table_display_name": table_display_name,
                "table_img_url": table_img_url,
                "table_description": table_description,
                "schema": convert_and_respect_annotation_metadata(
                    object_=schema, annotation=typing.Sequence[TableConfigInputSchemaItem], direction="write"
                ),
                "icon_emoji": icon_emoji,
                "icon_asset_url": icon_asset_url,
                "icon_fill": icon_fill,
                "singular_name": singular_name,
                "plural_name": plural_name,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SrcAppHttpRoutesCollectionCreateTableResponse,
                    construct_type(
                        type_=SrcAppHttpRoutesCollectionCreateTableResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def get(
        self, collection_id: str, table_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[SrcAppHttpRoutesCollectionGetTableResponse]:
        """
        Parameters
        ----------
        collection_id : str

        table_id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[SrcAppHttpRoutesCollectionGetTableResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/collections/{jsonable_encoder(collection_id)}/tables/{jsonable_encoder(table_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SrcAppHttpRoutesCollectionGetTableResponse,
                    construct_type(
                        type_=SrcAppHttpRoutesCollectionGetTableResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def update(
        self,
        collection_id: str,
        table_id: str,
        *,
        table_display_name: typing.Optional[str] = OMIT,
        table_img_url: typing.Optional[str] = OMIT,
        table_description: typing.Optional[str] = OMIT,
        schema: typing.Optional[typing.Sequence[TableDataSchemaItem]] = OMIT,
        icon_emoji: typing.Optional[str] = OMIT,
        icon_asset_url: typing.Optional[str] = OMIT,
        icon_fill: typing.Optional[str] = OMIT,
        singular_name: typing.Optional[str] = OMIT,
        plural_name: typing.Optional[str] = OMIT,
        index_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[SrcAppHttpRoutesCollectionUpdateTableResponse]:
        """
        Parameters
        ----------
        collection_id : str

        table_id : str

        table_display_name : typing.Optional[str]

        table_img_url : typing.Optional[str]

        table_description : typing.Optional[str]

        schema : typing.Optional[typing.Sequence[TableDataSchemaItem]]

        icon_emoji : typing.Optional[str]

        icon_asset_url : typing.Optional[str]

        icon_fill : typing.Optional[str]

        singular_name : typing.Optional[str]

        plural_name : typing.Optional[str]

        index_id : typing.Optional[str]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[SrcAppHttpRoutesCollectionUpdateTableResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/collections/{jsonable_encoder(collection_id)}/tables/{jsonable_encoder(table_id)}",
            method="PUT",
            json={
                "table_display_name": table_display_name,
                "table_img_url": table_img_url,
                "table_description": table_description,
                "schema": convert_and_respect_annotation_metadata(
                    object_=schema, annotation=typing.Sequence[TableDataSchemaItem], direction="write"
                ),
                "icon_emoji": icon_emoji,
                "icon_asset_url": icon_asset_url,
                "icon_fill": icon_fill,
                "singular_name": singular_name,
                "plural_name": plural_name,
                "index_id": index_id,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SrcAppHttpRoutesCollectionUpdateTableResponse,
                    construct_type(
                        type_=SrcAppHttpRoutesCollectionUpdateTableResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def delete(
        self, collection_id: str, table_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[SrcAppHttpRoutesCollectionDeleteTableResponse]:
        """
        Delete a table given a collection_id and table_id.

        Parameters
        ----------
        collection_id : str

        table_id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[SrcAppHttpRoutesCollectionDeleteTableResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/collections/{jsonable_encoder(collection_id)}/tables/{jsonable_encoder(table_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SrcAppHttpRoutesCollectionDeleteTableResponse,
                    construct_type(
                        type_=SrcAppHttpRoutesCollectionDeleteTableResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def get_schema(
        self, collection_id: str, table_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[SchemaResponse]:
        """
        Parameters
        ----------
        collection_id : str

        table_id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[SchemaResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/collections/{jsonable_encoder(collection_id)}/tables/{jsonable_encoder(table_id)}/schema",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SchemaResponse,
                    construct_type(
                        type_=SchemaResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def sync(
        self,
        collection_id: str,
        table_id: str,
        *,
        request: typing.Sequence[typing.Dict[str, typing.Optional[typing.Any]]],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[SrcAppHttpRoutesCollectionSyncTableResponse]:
        """
        Sync a table with a list of documents.

        Parameters
        ----------
        collection_id : str

        table_id : str

        request : typing.Sequence[typing.Dict[str, typing.Optional[typing.Any]]]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[SrcAppHttpRoutesCollectionSyncTableResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/collections/{jsonable_encoder(collection_id)}/tables/{jsonable_encoder(table_id)}/sync",
            method="POST",
            json=request,
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SrcAppHttpRoutesCollectionSyncTableResponse,
                    construct_type(
                        type_=SrcAppHttpRoutesCollectionSyncTableResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
