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

import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.document_response import DocumentResponse
from ..types.src_app_http_routes_collection_delete_documents_response import (
    SrcAppHttpRoutesCollectionDeleteDocumentsResponse,
)
from ..types.src_app_http_routes_collection_get_document_response import SrcAppHttpRoutesCollectionGetDocumentResponse
from ..types.src_app_http_routes_collection_get_documents_response import SrcAppHttpRoutesCollectionGetDocumentsResponse
from ..types.src_app_http_routes_collection_update_document_response import (
    SrcAppHttpRoutesCollectionUpdateDocumentResponse,
)
from .raw_client import AsyncRawDocumentsClient, RawDocumentsClient
from .types.documents_create_request_body import DocumentsCreateRequestBody
from .types.documents_update_batch_request_body import DocumentsUpdateBatchRequestBody
from .types.documents_update_request_value import DocumentsUpdateRequestValue

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


class DocumentsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawDocumentsClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> RawDocumentsClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawDocumentsClient
        """
        return self._raw_client

    def list(
        self,
        collection_id: str,
        table_id: str,
        *,
        limit: typing.Optional[int] = None,
        cursor: typing.Optional[str] = None,
        query: typing.Optional[str] = None,
        offset: typing.Optional[int] = None,
        sort_by: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SrcAppHttpRoutesCollectionGetDocumentsResponse:
        """
        Parameters
        ----------
        collection_id : str

        table_id : str

        limit : typing.Optional[int]
            Limit of records to return

        cursor : typing.Optional[str]
            Cursor to fetch next set of records

        query : typing.Optional[str]
            Search query

        offset : typing.Optional[int]
            Offset to fetch next set of records

        sort_by : typing.Optional[str]
            Sort by field

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

        Returns
        -------
        SrcAppHttpRoutesCollectionGetDocumentsResponse
            Successful Response

        Examples
        --------
        from scoutos import Scout

        client = Scout(
            api_key="YOUR_API_KEY",
        )
        client.documents.list(
            collection_id="collection_id",
            table_id="table_id",
            limit=1,
            cursor="cursor",
            query="query",
            offset=1,
            sort_by="sort_by",
        )
        """
        _response = self._raw_client.list(
            collection_id,
            table_id,
            limit=limit,
            cursor=cursor,
            query=query,
            offset=offset,
            sort_by=sort_by,
            request_options=request_options,
        )
        return _response.data

    def create(
        self,
        collection_id: str,
        table_id: str,
        *,
        request: DocumentsCreateRequestBody,
        job_id: typing.Optional[str] = None,
        sync_id: typing.Optional[str] = None,
        await_completion: typing.Optional[bool] = None,
        mode: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DocumentResponse:
        """
        Parameters
        ----------
        collection_id : str

        table_id : str

        request : DocumentsCreateRequestBody

        job_id : typing.Optional[str]
            The job id responsible for the document creation/update

        sync_id : typing.Optional[str]
            The sync id the job belongs to thats responsible for the document creation/update

        await_completion : typing.Optional[bool]
            Whether to wait for document creation/update to complete

        mode : typing.Optional[str]
            The mode to use for the document creation/update

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

        Returns
        -------
        DocumentResponse
            Successful Response

        Examples
        --------
        from scoutos import Scout

        client = Scout(
            api_key="YOUR_API_KEY",
        )
        client.documents.create(
            collection_id="collection_id",
            table_id="table_id",
            job_id="job_id",
            sync_id="sync_id",
            await_completion=True,
            mode="mode",
            request={"key": True},
        )
        """
        _response = self._raw_client.create(
            collection_id,
            table_id,
            request=request,
            job_id=job_id,
            sync_id=sync_id,
            await_completion=await_completion,
            mode=mode,
            request_options=request_options,
        )
        return _response.data

    def update_batch(
        self,
        collection_id: str,
        table_id: str,
        *,
        request: DocumentsUpdateBatchRequestBody,
        job_id: typing.Optional[str] = None,
        sync_id: typing.Optional[str] = None,
        await_completion: typing.Optional[bool] = None,
        mode: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DocumentResponse:
        """
        Parameters
        ----------
        collection_id : str

        table_id : str

        request : DocumentsUpdateBatchRequestBody

        job_id : typing.Optional[str]
            The job id responsible for the document creation/update

        sync_id : typing.Optional[str]
            The sync id the job belongs to thats responsible for the document creation/update

        await_completion : typing.Optional[bool]
            Whether to wait for document creation/update to complete

        mode : typing.Optional[str]
            The mode to use for the document creation/update

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

        Returns
        -------
        DocumentResponse
            Successful Response

        Examples
        --------
        from scoutos import Scout

        client = Scout(
            api_key="YOUR_API_KEY",
        )
        client.documents.update_batch(
            collection_id="collection_id",
            table_id="table_id",
            job_id="job_id",
            sync_id="sync_id",
            await_completion=True,
            mode="mode",
            request={"key": True},
        )
        """
        _response = self._raw_client.update_batch(
            collection_id,
            table_id,
            request=request,
            job_id=job_id,
            sync_id=sync_id,
            await_completion=await_completion,
            mode=mode,
            request_options=request_options,
        )
        return _response.data

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

        table_id : str

        document_id : str

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

        Returns
        -------
        SrcAppHttpRoutesCollectionGetDocumentResponse
            Successful Response

        Examples
        --------
        from scoutos import Scout

        client = Scout(
            api_key="YOUR_API_KEY",
        )
        client.documents.get(
            collection_id="collection_id",
            table_id="table_id",
            document_id="document_id",
        )
        """
        _response = self._raw_client.get(collection_id, table_id, document_id, request_options=request_options)
        return _response.data

    def update(
        self,
        collection_id: str,
        table_id: str,
        document_id: str,
        *,
        request: typing.Dict[str, typing.Optional[DocumentsUpdateRequestValue]],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SrcAppHttpRoutesCollectionUpdateDocumentResponse:
        """
        Parameters
        ----------
        collection_id : str

        table_id : str

        document_id : str

        request : typing.Dict[str, typing.Optional[DocumentsUpdateRequestValue]]

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

        Returns
        -------
        SrcAppHttpRoutesCollectionUpdateDocumentResponse
            Successful Response

        Examples
        --------
        from scoutos import Scout

        client = Scout(
            api_key="YOUR_API_KEY",
        )
        client.documents.update(
            collection_id="collection_id",
            table_id="table_id",
            document_id="document_id",
            request={},
        )
        """
        _response = self._raw_client.update(
            collection_id, table_id, document_id, request=request, request_options=request_options
        )
        return _response.data

    def delete(
        self,
        collection_id: str,
        table_id: str,
        document_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SrcAppHttpRoutesCollectionDeleteDocumentsResponse:
        """
        Parameters
        ----------
        collection_id : str

        table_id : str

        document_id : str

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

        Returns
        -------
        SrcAppHttpRoutesCollectionDeleteDocumentsResponse
            Successful Response

        Examples
        --------
        from scoutos import Scout

        client = Scout(
            api_key="YOUR_API_KEY",
        )
        client.documents.delete(
            collection_id="collection_id",
            table_id="table_id",
            document_id="document_id",
        )
        """
        _response = self._raw_client.delete(collection_id, table_id, document_id, request_options=request_options)
        return _response.data

    def delete_batch(
        self,
        collection_id: str,
        table_id: str,
        *,
        request: typing.Sequence[str],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SrcAppHttpRoutesCollectionDeleteDocumentsResponse:
        """
        Delete documents given a list of document ids.

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

        table_id : str

        request : typing.Sequence[str]

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

        Returns
        -------
        SrcAppHttpRoutesCollectionDeleteDocumentsResponse
            Successful Response

        Examples
        --------
        from scoutos import Scout

        client = Scout(
            api_key="YOUR_API_KEY",
        )
        client.documents.delete_batch(
            collection_id="collection_id",
            table_id="table_id",
            request=["string"],
        )
        """
        _response = self._raw_client.delete_batch(
            collection_id, table_id, request=request, request_options=request_options
        )
        return _response.data


class AsyncDocumentsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawDocumentsClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> AsyncRawDocumentsClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawDocumentsClient
        """
        return self._raw_client

    async def list(
        self,
        collection_id: str,
        table_id: str,
        *,
        limit: typing.Optional[int] = None,
        cursor: typing.Optional[str] = None,
        query: typing.Optional[str] = None,
        offset: typing.Optional[int] = None,
        sort_by: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SrcAppHttpRoutesCollectionGetDocumentsResponse:
        """
        Parameters
        ----------
        collection_id : str

        table_id : str

        limit : typing.Optional[int]
            Limit of records to return

        cursor : typing.Optional[str]
            Cursor to fetch next set of records

        query : typing.Optional[str]
            Search query

        offset : typing.Optional[int]
            Offset to fetch next set of records

        sort_by : typing.Optional[str]
            Sort by field

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

        Returns
        -------
        SrcAppHttpRoutesCollectionGetDocumentsResponse
            Successful Response

        Examples
        --------
        import asyncio

        from scoutos import AsyncScout

        client = AsyncScout(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.documents.list(
                collection_id="collection_id",
                table_id="table_id",
                limit=1,
                cursor="cursor",
                query="query",
                offset=1,
                sort_by="sort_by",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list(
            collection_id,
            table_id,
            limit=limit,
            cursor=cursor,
            query=query,
            offset=offset,
            sort_by=sort_by,
            request_options=request_options,
        )
        return _response.data

    async def create(
        self,
        collection_id: str,
        table_id: str,
        *,
        request: DocumentsCreateRequestBody,
        job_id: typing.Optional[str] = None,
        sync_id: typing.Optional[str] = None,
        await_completion: typing.Optional[bool] = None,
        mode: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DocumentResponse:
        """
        Parameters
        ----------
        collection_id : str

        table_id : str

        request : DocumentsCreateRequestBody

        job_id : typing.Optional[str]
            The job id responsible for the document creation/update

        sync_id : typing.Optional[str]
            The sync id the job belongs to thats responsible for the document creation/update

        await_completion : typing.Optional[bool]
            Whether to wait for document creation/update to complete

        mode : typing.Optional[str]
            The mode to use for the document creation/update

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

        Returns
        -------
        DocumentResponse
            Successful Response

        Examples
        --------
        import asyncio

        from scoutos import AsyncScout

        client = AsyncScout(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.documents.create(
                collection_id="collection_id",
                table_id="table_id",
                job_id="job_id",
                sync_id="sync_id",
                await_completion=True,
                mode="mode",
                request={"key": True},
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            collection_id,
            table_id,
            request=request,
            job_id=job_id,
            sync_id=sync_id,
            await_completion=await_completion,
            mode=mode,
            request_options=request_options,
        )
        return _response.data

    async def update_batch(
        self,
        collection_id: str,
        table_id: str,
        *,
        request: DocumentsUpdateBatchRequestBody,
        job_id: typing.Optional[str] = None,
        sync_id: typing.Optional[str] = None,
        await_completion: typing.Optional[bool] = None,
        mode: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DocumentResponse:
        """
        Parameters
        ----------
        collection_id : str

        table_id : str

        request : DocumentsUpdateBatchRequestBody

        job_id : typing.Optional[str]
            The job id responsible for the document creation/update

        sync_id : typing.Optional[str]
            The sync id the job belongs to thats responsible for the document creation/update

        await_completion : typing.Optional[bool]
            Whether to wait for document creation/update to complete

        mode : typing.Optional[str]
            The mode to use for the document creation/update

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

        Returns
        -------
        DocumentResponse
            Successful Response

        Examples
        --------
        import asyncio

        from scoutos import AsyncScout

        client = AsyncScout(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.documents.update_batch(
                collection_id="collection_id",
                table_id="table_id",
                job_id="job_id",
                sync_id="sync_id",
                await_completion=True,
                mode="mode",
                request={"key": True},
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_batch(
            collection_id,
            table_id,
            request=request,
            job_id=job_id,
            sync_id=sync_id,
            await_completion=await_completion,
            mode=mode,
            request_options=request_options,
        )
        return _response.data

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

        table_id : str

        document_id : str

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

        Returns
        -------
        SrcAppHttpRoutesCollectionGetDocumentResponse
            Successful Response

        Examples
        --------
        import asyncio

        from scoutos import AsyncScout

        client = AsyncScout(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.documents.get(
                collection_id="collection_id",
                table_id="table_id",
                document_id="document_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get(collection_id, table_id, document_id, request_options=request_options)
        return _response.data

    async def update(
        self,
        collection_id: str,
        table_id: str,
        document_id: str,
        *,
        request: typing.Dict[str, typing.Optional[DocumentsUpdateRequestValue]],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SrcAppHttpRoutesCollectionUpdateDocumentResponse:
        """
        Parameters
        ----------
        collection_id : str

        table_id : str

        document_id : str

        request : typing.Dict[str, typing.Optional[DocumentsUpdateRequestValue]]

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

        Returns
        -------
        SrcAppHttpRoutesCollectionUpdateDocumentResponse
            Successful Response

        Examples
        --------
        import asyncio

        from scoutos import AsyncScout

        client = AsyncScout(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.documents.update(
                collection_id="collection_id",
                table_id="table_id",
                document_id="document_id",
                request={},
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update(
            collection_id, table_id, document_id, request=request, request_options=request_options
        )
        return _response.data

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

        table_id : str

        document_id : str

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

        Returns
        -------
        SrcAppHttpRoutesCollectionDeleteDocumentsResponse
            Successful Response

        Examples
        --------
        import asyncio

        from scoutos import AsyncScout

        client = AsyncScout(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.documents.delete(
                collection_id="collection_id",
                table_id="table_id",
                document_id="document_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.delete(collection_id, table_id, document_id, request_options=request_options)
        return _response.data

    async def delete_batch(
        self,
        collection_id: str,
        table_id: str,
        *,
        request: typing.Sequence[str],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SrcAppHttpRoutesCollectionDeleteDocumentsResponse:
        """
        Delete documents given a list of document ids.

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

        table_id : str

        request : typing.Sequence[str]

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

        Returns
        -------
        SrcAppHttpRoutesCollectionDeleteDocumentsResponse
            Successful Response

        Examples
        --------
        import asyncio

        from scoutos import AsyncScout

        client = AsyncScout(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.documents.delete_batch(
                collection_id="collection_id",
                table_id="table_id",
                request=["string"],
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.delete_batch(
            collection_id, table_id, request=request, request_options=request_options
        )
        return _response.data
