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

import typing
import urllib.parse
import uuid
from json.decoder import JSONDecodeError

from ..common.types.collaborator import Collaborator
from ..common.types.resource_identifier import ResourceIdentifier
from ..core.api_error import ApiError
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.jsonable_encoder import jsonable_encoder
from ..core.pydantic_utilities import pydantic_v1
from ..core.query_encoder import encode_query
from ..core.remove_none_from_dict import remove_none_from_dict
from ..core.request_options import RequestOptions
from .types.create_collection_response import CreateCollectionResponse
from .types.delete_collection_response import DeleteCollectionResponse
from .types.mongo_collection_sync_config import MongoCollectionSyncConfig
from .types.mongo_collection_sync_response import MongoCollectionSyncResponse

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


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

    def add_documents_to_collection(
        self,
        *,
        collection_id: uuid.UUID,
        resource_identifiers: typing.Sequence[ResourceIdentifier],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Add documents to a document collection. Note that the documents must already exist in the document catalog to use this endpoint. If you want to upload a new document to a collection, use the `uploadDocumentContents` endpoint.

        Parameters
        ----------
        collection_id : uuid.UUID
            The ID of the document collection you want to add to.

        resource_identifiers : typing.Sequence[ResourceIdentifier]
            The set of resource identifier for which you want to add to the collection.


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

        Returns
        -------
        None

        Examples
        --------
        import uuid

        from credal import ResourceIdentifier_ExternalResourceId
        from credal.client import CredalApi

        client = CredalApi(
            api_key="YOUR_API_KEY",
        )
        client.document_collections.add_documents_to_collection(
            collection_id=uuid.UUID(
                "82e4b12a-6990-45d4-8ebd-85c00e030c24",
            ),
            resource_identifiers=[
                ResourceIdentifier_ExternalResourceId(
                    external_resource_id="170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr",
                    resource_type="GOOGLE_DRIVE_ITEM",
                ),
                ResourceIdentifier_ExternalResourceId(
                    external_resource_id="398KAHdfkjsdf09r54UvyslPVWkQFOA0lOiu34in923",
                    resource_type="GOOGLE_DRIVE_ITEM",
                ),
            ],
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            method="POST",
            url=urllib.parse.urljoin(
                f"{self._client_wrapper.get_base_url()}/", "v0/documentCollections/addDocumentsToCollection"
            ),
            params=encode_query(
                jsonable_encoder(
                    request_options.get("additional_query_parameters") if request_options is not None else None
                )
            ),
            json=jsonable_encoder({"collectionId": collection_id, "resourceIdentifiers": resource_identifiers})
            if request_options is None or request_options.get("additional_body_parameters") is None
            else {
                **jsonable_encoder({"collectionId": collection_id, "resourceIdentifiers": resource_identifiers}),
                **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))),
            },
            headers=jsonable_encoder(
                remove_none_from_dict(
                    {
                        **self._client_wrapper.get_headers(),
                        **(request_options.get("additional_headers", {}) if request_options is not None else {}),
                    }
                )
            ),
            timeout=request_options.get("timeout_in_seconds")
            if request_options is not None and request_options.get("timeout_in_seconds") is not None
            else self._client_wrapper.get_timeout(),
            retries=0,
            max_retries=request_options.get("max_retries") if request_options is not None else 0,  # type: ignore
        )
        if 200 <= _response.status_code < 300:
            return
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def remove_documents_from_collection(
        self,
        *,
        collection_id: uuid.UUID,
        resource_identifiers: typing.Sequence[ResourceIdentifier],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Remove documents from a collection

        Parameters
        ----------
        collection_id : uuid.UUID
            The ID of the document collection you want to add to.

        resource_identifiers : typing.Sequence[ResourceIdentifier]
            The set of resource identifier for which you want to remove from the collection


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

        Returns
        -------
        None

        Examples
        --------
        import uuid

        from credal import ResourceIdentifier_ExternalResourceId
        from credal.client import CredalApi

        client = CredalApi(
            api_key="YOUR_API_KEY",
        )
        client.document_collections.remove_documents_from_collection(
            collection_id=uuid.UUID(
                "82e4b12a-6990-45d4-8ebd-85c00e030c24",
            ),
            resource_identifiers=[
                ResourceIdentifier_ExternalResourceId(
                    external_resource_id="170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr",
                    resource_type="GOOGLE_DRIVE_ITEM",
                ),
                ResourceIdentifier_ExternalResourceId(
                    external_resource_id="398KAHdfkjsdf09r54UvyslPVWkQFOA0lOiu34in923",
                    resource_type="GOOGLE_DRIVE_ITEM",
                ),
            ],
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            method="DELETE",
            url=urllib.parse.urljoin(
                f"{self._client_wrapper.get_base_url()}/", "v0/documentCollections/removeDocumentsFromCollection"
            ),
            params=encode_query(
                jsonable_encoder(
                    request_options.get("additional_query_parameters") if request_options is not None else None
                )
            ),
            json=jsonable_encoder({"collectionId": collection_id, "resourceIdentifiers": resource_identifiers})
            if request_options is None or request_options.get("additional_body_parameters") is None
            else {
                **jsonable_encoder({"collectionId": collection_id, "resourceIdentifiers": resource_identifiers}),
                **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))),
            },
            headers=jsonable_encoder(
                remove_none_from_dict(
                    {
                        **self._client_wrapper.get_headers(),
                        **(request_options.get("additional_headers", {}) if request_options is not None else {}),
                    }
                )
            ),
            timeout=request_options.get("timeout_in_seconds")
            if request_options is not None and request_options.get("timeout_in_seconds") is not None
            else self._client_wrapper.get_timeout(),
            retries=0,
            max_retries=request_options.get("max_retries") if request_options is not None else 0,  # type: ignore
        )
        if 200 <= _response.status_code < 300:
            return
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def create_collection(
        self,
        *,
        name: str,
        description: str,
        collaborators: typing.Sequence[Collaborator],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateCollectionResponse:
        """
        Create a new copilot. The API key used will be added to the copilot for future Requests

        Parameters
        ----------
        name : str
            A descriptive name for the collection.


        description : str
            An in depth name for the copilot's function. Useful for routing requests to the right copilot.


        collaborators : typing.Sequence[Collaborator]
            A list of collaborator emails and roles that will have access to the copilot.


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

        Returns
        -------
        CreateCollectionResponse

        Examples
        --------
        from credal import Collaborator
        from credal.client import CredalApi

        client = CredalApi(
            api_key="YOUR_API_KEY",
        )
        client.document_collections.create_collection(
            name="Customer Collection",
            description="This collection is used to answer customer requests based on internal documentation.",
            collaborators=[
                Collaborator(
                    email="test@gmail.com",
                    role="editor",
                )
            ],
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            method="POST",
            url=urllib.parse.urljoin(
                f"{self._client_wrapper.get_base_url()}/", "v0/documentCollections/createCollection"
            ),
            params=encode_query(
                jsonable_encoder(
                    request_options.get("additional_query_parameters") if request_options is not None else None
                )
            ),
            json=jsonable_encoder({"name": name, "description": description, "collaborators": collaborators})
            if request_options is None or request_options.get("additional_body_parameters") is None
            else {
                **jsonable_encoder({"name": name, "description": description, "collaborators": collaborators}),
                **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))),
            },
            headers=jsonable_encoder(
                remove_none_from_dict(
                    {
                        **self._client_wrapper.get_headers(),
                        **(request_options.get("additional_headers", {}) if request_options is not None else {}),
                    }
                )
            ),
            timeout=request_options.get("timeout_in_seconds")
            if request_options is not None and request_options.get("timeout_in_seconds") is not None
            else self._client_wrapper.get_timeout(),
            retries=0,
            max_retries=request_options.get("max_retries") if request_options is not None else 0,  # type: ignore
        )
        if 200 <= _response.status_code < 300:
            return pydantic_v1.parse_obj_as(CreateCollectionResponse, _response.json())  # type: ignore
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def delete_collection(
        self, *, collection_id: uuid.UUID, request_options: typing.Optional[RequestOptions] = None
    ) -> DeleteCollectionResponse:
        """
        Delete the collection.

        Parameters
        ----------
        collection_id : uuid.UUID

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

        Returns
        -------
        DeleteCollectionResponse

        Examples
        --------
        import uuid

        from credal.client import CredalApi

        client = CredalApi(
            api_key="YOUR_API_KEY",
        )
        client.document_collections.delete_collection(
            collection_id=uuid.UUID(
                "ac20e6ba-0bae-11ef-b25a-efca73df4c3a",
            ),
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            method="DELETE",
            url=urllib.parse.urljoin(
                f"{self._client_wrapper.get_base_url()}/", "v0/documentCollections/deleteCollection"
            ),
            params=encode_query(
                jsonable_encoder(
                    request_options.get("additional_query_parameters") if request_options is not None else None
                )
            ),
            json=jsonable_encoder({"collectionId": collection_id})
            if request_options is None or request_options.get("additional_body_parameters") is None
            else {
                **jsonable_encoder({"collectionId": collection_id}),
                **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))),
            },
            headers=jsonable_encoder(
                remove_none_from_dict(
                    {
                        **self._client_wrapper.get_headers(),
                        **(request_options.get("additional_headers", {}) if request_options is not None else {}),
                    }
                )
            ),
            timeout=request_options.get("timeout_in_seconds")
            if request_options is not None and request_options.get("timeout_in_seconds") is not None
            else self._client_wrapper.get_timeout(),
            retries=0,
            max_retries=request_options.get("max_retries") if request_options is not None else 0,  # type: ignore
        )
        if 200 <= _response.status_code < 300:
            return pydantic_v1.parse_obj_as(DeleteCollectionResponse, _response.json())  # type: ignore
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def create_mongo_collection_sync(
        self,
        *,
        collection_id: uuid.UUID,
        mongo_uri: str,
        config: MongoCollectionSyncConfig,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> MongoCollectionSyncResponse:
        """
        Credal lets you easily sync your MongoDB data for use in Collections and Copilots. Create a new sync from a MongoDB collection to a Credal collection.

        Parameters
        ----------
        collection_id : uuid.UUID

        mongo_uri : str

        config : MongoCollectionSyncConfig

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

        Returns
        -------
        MongoCollectionSyncResponse

        Examples
        --------
        import uuid

        from credal import MongoCollectionSyncConfig, MongoSourceFieldsConfig
        from credal.client import CredalApi

        client = CredalApi(
            api_key="YOUR_API_KEY",
        )
        client.document_collections.create_mongo_collection_sync(
            mongo_uri="mongodb+srv://cluster0.hzwklqn.mongodb.net/Cluster0?retryWrites=true&w=majority",
            collection_id=uuid.UUID(
                "ac20e6ba-0bae-11ef-b25a-efca73df4c3a",
            ),
            config=MongoCollectionSyncConfig(
                sync_name="My sales transcripts",
                collection_name="myCollection",
                filter_expression={"status": {"$ne": "disabled"}},
                source_fields=MongoSourceFieldsConfig(
                    body="body",
                    source_name="meetingName",
                    source_system_updated="transcriptDatetime",
                    source_url="link",
                ),
            ),
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            method="POST",
            url=urllib.parse.urljoin(
                f"{self._client_wrapper.get_base_url()}/", "v0/documentCollections/mongodb/createMongoSync"
            ),
            params=encode_query(
                jsonable_encoder(
                    request_options.get("additional_query_parameters") if request_options is not None else None
                )
            ),
            json=jsonable_encoder({"collectionId": collection_id, "mongoURI": mongo_uri, "config": config})
            if request_options is None or request_options.get("additional_body_parameters") is None
            else {
                **jsonable_encoder({"collectionId": collection_id, "mongoURI": mongo_uri, "config": config}),
                **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))),
            },
            headers=jsonable_encoder(
                remove_none_from_dict(
                    {
                        **self._client_wrapper.get_headers(),
                        **(request_options.get("additional_headers", {}) if request_options is not None else {}),
                    }
                )
            ),
            timeout=request_options.get("timeout_in_seconds")
            if request_options is not None and request_options.get("timeout_in_seconds") is not None
            else self._client_wrapper.get_timeout(),
            retries=0,
            max_retries=request_options.get("max_retries") if request_options is not None else 0,  # type: ignore
        )
        if 200 <= _response.status_code < 300:
            return pydantic_v1.parse_obj_as(MongoCollectionSyncResponse, _response.json())  # type: ignore
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def update_mongo_collection_sync(
        self,
        *,
        mongo_credential_id: uuid.UUID,
        mongo_uri: str,
        config: MongoCollectionSyncConfig,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> MongoCollectionSyncResponse:
        """
        Credal lets you easily sync your MongoDB data for use in Collections and Copilots. Update an existing sync from a MongoDB collection to a Credal collection via the `mongoCredentialId`, to disambiguate between multiple potential syncs to a given collection.

        Parameters
        ----------
        mongo_credential_id : uuid.UUID

        mongo_uri : str

        config : MongoCollectionSyncConfig

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

        Returns
        -------
        MongoCollectionSyncResponse

        Examples
        --------
        import uuid

        from credal import MongoCollectionSyncConfig, MongoSourceFieldsConfig
        from credal.client import CredalApi

        client = CredalApi(
            api_key="YOUR_API_KEY",
        )
        client.document_collections.update_mongo_collection_sync(
            mongo_uri="mongodb+srv://cluster0.hzwklqn.mongodb.net/Cluster0?retryWrites=true&w=majority",
            mongo_credential_id=uuid.UUID(
                "5988ed76-6ee1-11ef-97dd-1fca54b7c4bc",
            ),
            config=MongoCollectionSyncConfig(
                sync_name="My recent summarized sales transcripts",
                collection_name="myCollection",
                filter_expression={
                    "transcriptDatetime": {"$gt": "2023-01-01T00:00:00.000Z"}
                },
                source_fields=MongoSourceFieldsConfig(
                    body="transcriptSummary",
                    source_name="meetingName",
                    source_system_updated="transcriptDatetime",
                    source_url="link",
                ),
            ),
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            method="POST",
            url=urllib.parse.urljoin(
                f"{self._client_wrapper.get_base_url()}/", "v0/documentCollections/mongodb/updateMongoSync"
            ),
            params=encode_query(
                jsonable_encoder(
                    request_options.get("additional_query_parameters") if request_options is not None else None
                )
            ),
            json=jsonable_encoder({"mongoCredentialId": mongo_credential_id, "mongoURI": mongo_uri, "config": config})
            if request_options is None or request_options.get("additional_body_parameters") is None
            else {
                **jsonable_encoder({"mongoCredentialId": mongo_credential_id, "mongoURI": mongo_uri, "config": config}),
                **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))),
            },
            headers=jsonable_encoder(
                remove_none_from_dict(
                    {
                        **self._client_wrapper.get_headers(),
                        **(request_options.get("additional_headers", {}) if request_options is not None else {}),
                    }
                )
            ),
            timeout=request_options.get("timeout_in_seconds")
            if request_options is not None and request_options.get("timeout_in_seconds") is not None
            else self._client_wrapper.get_timeout(),
            retries=0,
            max_retries=request_options.get("max_retries") if request_options is not None else 0,  # type: ignore
        )
        if 200 <= _response.status_code < 300:
            return pydantic_v1.parse_obj_as(MongoCollectionSyncResponse, _response.json())  # type: ignore
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)


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

    async def add_documents_to_collection(
        self,
        *,
        collection_id: uuid.UUID,
        resource_identifiers: typing.Sequence[ResourceIdentifier],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Add documents to a document collection. Note that the documents must already exist in the document catalog to use this endpoint. If you want to upload a new document to a collection, use the `uploadDocumentContents` endpoint.

        Parameters
        ----------
        collection_id : uuid.UUID
            The ID of the document collection you want to add to.

        resource_identifiers : typing.Sequence[ResourceIdentifier]
            The set of resource identifier for which you want to add to the collection.


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

        Returns
        -------
        None

        Examples
        --------
        import uuid

        from credal import ResourceIdentifier_ExternalResourceId
        from credal.client import AsyncCredalApi

        client = AsyncCredalApi(
            api_key="YOUR_API_KEY",
        )
        await client.document_collections.add_documents_to_collection(
            collection_id=uuid.UUID(
                "82e4b12a-6990-45d4-8ebd-85c00e030c24",
            ),
            resource_identifiers=[
                ResourceIdentifier_ExternalResourceId(
                    external_resource_id="170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr",
                    resource_type="GOOGLE_DRIVE_ITEM",
                ),
                ResourceIdentifier_ExternalResourceId(
                    external_resource_id="398KAHdfkjsdf09r54UvyslPVWkQFOA0lOiu34in923",
                    resource_type="GOOGLE_DRIVE_ITEM",
                ),
            ],
        )
        """
        _response = await self._client_wrapper.httpx_client.request(
            method="POST",
            url=urllib.parse.urljoin(
                f"{self._client_wrapper.get_base_url()}/", "v0/documentCollections/addDocumentsToCollection"
            ),
            params=encode_query(
                jsonable_encoder(
                    request_options.get("additional_query_parameters") if request_options is not None else None
                )
            ),
            json=jsonable_encoder({"collectionId": collection_id, "resourceIdentifiers": resource_identifiers})
            if request_options is None or request_options.get("additional_body_parameters") is None
            else {
                **jsonable_encoder({"collectionId": collection_id, "resourceIdentifiers": resource_identifiers}),
                **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))),
            },
            headers=jsonable_encoder(
                remove_none_from_dict(
                    {
                        **self._client_wrapper.get_headers(),
                        **(request_options.get("additional_headers", {}) if request_options is not None else {}),
                    }
                )
            ),
            timeout=request_options.get("timeout_in_seconds")
            if request_options is not None and request_options.get("timeout_in_seconds") is not None
            else self._client_wrapper.get_timeout(),
            retries=0,
            max_retries=request_options.get("max_retries") if request_options is not None else 0,  # type: ignore
        )
        if 200 <= _response.status_code < 300:
            return
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def remove_documents_from_collection(
        self,
        *,
        collection_id: uuid.UUID,
        resource_identifiers: typing.Sequence[ResourceIdentifier],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Remove documents from a collection

        Parameters
        ----------
        collection_id : uuid.UUID
            The ID of the document collection you want to add to.

        resource_identifiers : typing.Sequence[ResourceIdentifier]
            The set of resource identifier for which you want to remove from the collection


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

        Returns
        -------
        None

        Examples
        --------
        import uuid

        from credal import ResourceIdentifier_ExternalResourceId
        from credal.client import AsyncCredalApi

        client = AsyncCredalApi(
            api_key="YOUR_API_KEY",
        )
        await client.document_collections.remove_documents_from_collection(
            collection_id=uuid.UUID(
                "82e4b12a-6990-45d4-8ebd-85c00e030c24",
            ),
            resource_identifiers=[
                ResourceIdentifier_ExternalResourceId(
                    external_resource_id="170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr",
                    resource_type="GOOGLE_DRIVE_ITEM",
                ),
                ResourceIdentifier_ExternalResourceId(
                    external_resource_id="398KAHdfkjsdf09r54UvyslPVWkQFOA0lOiu34in923",
                    resource_type="GOOGLE_DRIVE_ITEM",
                ),
            ],
        )
        """
        _response = await self._client_wrapper.httpx_client.request(
            method="DELETE",
            url=urllib.parse.urljoin(
                f"{self._client_wrapper.get_base_url()}/", "v0/documentCollections/removeDocumentsFromCollection"
            ),
            params=encode_query(
                jsonable_encoder(
                    request_options.get("additional_query_parameters") if request_options is not None else None
                )
            ),
            json=jsonable_encoder({"collectionId": collection_id, "resourceIdentifiers": resource_identifiers})
            if request_options is None or request_options.get("additional_body_parameters") is None
            else {
                **jsonable_encoder({"collectionId": collection_id, "resourceIdentifiers": resource_identifiers}),
                **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))),
            },
            headers=jsonable_encoder(
                remove_none_from_dict(
                    {
                        **self._client_wrapper.get_headers(),
                        **(request_options.get("additional_headers", {}) if request_options is not None else {}),
                    }
                )
            ),
            timeout=request_options.get("timeout_in_seconds")
            if request_options is not None and request_options.get("timeout_in_seconds") is not None
            else self._client_wrapper.get_timeout(),
            retries=0,
            max_retries=request_options.get("max_retries") if request_options is not None else 0,  # type: ignore
        )
        if 200 <= _response.status_code < 300:
            return
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def create_collection(
        self,
        *,
        name: str,
        description: str,
        collaborators: typing.Sequence[Collaborator],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateCollectionResponse:
        """
        Create a new copilot. The API key used will be added to the copilot for future Requests

        Parameters
        ----------
        name : str
            A descriptive name for the collection.


        description : str
            An in depth name for the copilot's function. Useful for routing requests to the right copilot.


        collaborators : typing.Sequence[Collaborator]
            A list of collaborator emails and roles that will have access to the copilot.


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

        Returns
        -------
        CreateCollectionResponse

        Examples
        --------
        from credal import Collaborator
        from credal.client import AsyncCredalApi

        client = AsyncCredalApi(
            api_key="YOUR_API_KEY",
        )
        await client.document_collections.create_collection(
            name="Customer Collection",
            description="This collection is used to answer customer requests based on internal documentation.",
            collaborators=[
                Collaborator(
                    email="test@gmail.com",
                    role="editor",
                )
            ],
        )
        """
        _response = await self._client_wrapper.httpx_client.request(
            method="POST",
            url=urllib.parse.urljoin(
                f"{self._client_wrapper.get_base_url()}/", "v0/documentCollections/createCollection"
            ),
            params=encode_query(
                jsonable_encoder(
                    request_options.get("additional_query_parameters") if request_options is not None else None
                )
            ),
            json=jsonable_encoder({"name": name, "description": description, "collaborators": collaborators})
            if request_options is None or request_options.get("additional_body_parameters") is None
            else {
                **jsonable_encoder({"name": name, "description": description, "collaborators": collaborators}),
                **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))),
            },
            headers=jsonable_encoder(
                remove_none_from_dict(
                    {
                        **self._client_wrapper.get_headers(),
                        **(request_options.get("additional_headers", {}) if request_options is not None else {}),
                    }
                )
            ),
            timeout=request_options.get("timeout_in_seconds")
            if request_options is not None and request_options.get("timeout_in_seconds") is not None
            else self._client_wrapper.get_timeout(),
            retries=0,
            max_retries=request_options.get("max_retries") if request_options is not None else 0,  # type: ignore
        )
        if 200 <= _response.status_code < 300:
            return pydantic_v1.parse_obj_as(CreateCollectionResponse, _response.json())  # type: ignore
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def delete_collection(
        self, *, collection_id: uuid.UUID, request_options: typing.Optional[RequestOptions] = None
    ) -> DeleteCollectionResponse:
        """
        Delete the collection.

        Parameters
        ----------
        collection_id : uuid.UUID

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

        Returns
        -------
        DeleteCollectionResponse

        Examples
        --------
        import uuid

        from credal.client import AsyncCredalApi

        client = AsyncCredalApi(
            api_key="YOUR_API_KEY",
        )
        await client.document_collections.delete_collection(
            collection_id=uuid.UUID(
                "ac20e6ba-0bae-11ef-b25a-efca73df4c3a",
            ),
        )
        """
        _response = await self._client_wrapper.httpx_client.request(
            method="DELETE",
            url=urllib.parse.urljoin(
                f"{self._client_wrapper.get_base_url()}/", "v0/documentCollections/deleteCollection"
            ),
            params=encode_query(
                jsonable_encoder(
                    request_options.get("additional_query_parameters") if request_options is not None else None
                )
            ),
            json=jsonable_encoder({"collectionId": collection_id})
            if request_options is None or request_options.get("additional_body_parameters") is None
            else {
                **jsonable_encoder({"collectionId": collection_id}),
                **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))),
            },
            headers=jsonable_encoder(
                remove_none_from_dict(
                    {
                        **self._client_wrapper.get_headers(),
                        **(request_options.get("additional_headers", {}) if request_options is not None else {}),
                    }
                )
            ),
            timeout=request_options.get("timeout_in_seconds")
            if request_options is not None and request_options.get("timeout_in_seconds") is not None
            else self._client_wrapper.get_timeout(),
            retries=0,
            max_retries=request_options.get("max_retries") if request_options is not None else 0,  # type: ignore
        )
        if 200 <= _response.status_code < 300:
            return pydantic_v1.parse_obj_as(DeleteCollectionResponse, _response.json())  # type: ignore
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def create_mongo_collection_sync(
        self,
        *,
        collection_id: uuid.UUID,
        mongo_uri: str,
        config: MongoCollectionSyncConfig,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> MongoCollectionSyncResponse:
        """
        Credal lets you easily sync your MongoDB data for use in Collections and Copilots. Create a new sync from a MongoDB collection to a Credal collection.

        Parameters
        ----------
        collection_id : uuid.UUID

        mongo_uri : str

        config : MongoCollectionSyncConfig

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

        Returns
        -------
        MongoCollectionSyncResponse

        Examples
        --------
        import uuid

        from credal import MongoCollectionSyncConfig, MongoSourceFieldsConfig
        from credal.client import AsyncCredalApi

        client = AsyncCredalApi(
            api_key="YOUR_API_KEY",
        )
        await client.document_collections.create_mongo_collection_sync(
            mongo_uri="mongodb+srv://cluster0.hzwklqn.mongodb.net/Cluster0?retryWrites=true&w=majority",
            collection_id=uuid.UUID(
                "ac20e6ba-0bae-11ef-b25a-efca73df4c3a",
            ),
            config=MongoCollectionSyncConfig(
                sync_name="My sales transcripts",
                collection_name="myCollection",
                filter_expression={"status": {"$ne": "disabled"}},
                source_fields=MongoSourceFieldsConfig(
                    body="body",
                    source_name="meetingName",
                    source_system_updated="transcriptDatetime",
                    source_url="link",
                ),
            ),
        )
        """
        _response = await self._client_wrapper.httpx_client.request(
            method="POST",
            url=urllib.parse.urljoin(
                f"{self._client_wrapper.get_base_url()}/", "v0/documentCollections/mongodb/createMongoSync"
            ),
            params=encode_query(
                jsonable_encoder(
                    request_options.get("additional_query_parameters") if request_options is not None else None
                )
            ),
            json=jsonable_encoder({"collectionId": collection_id, "mongoURI": mongo_uri, "config": config})
            if request_options is None or request_options.get("additional_body_parameters") is None
            else {
                **jsonable_encoder({"collectionId": collection_id, "mongoURI": mongo_uri, "config": config}),
                **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))),
            },
            headers=jsonable_encoder(
                remove_none_from_dict(
                    {
                        **self._client_wrapper.get_headers(),
                        **(request_options.get("additional_headers", {}) if request_options is not None else {}),
                    }
                )
            ),
            timeout=request_options.get("timeout_in_seconds")
            if request_options is not None and request_options.get("timeout_in_seconds") is not None
            else self._client_wrapper.get_timeout(),
            retries=0,
            max_retries=request_options.get("max_retries") if request_options is not None else 0,  # type: ignore
        )
        if 200 <= _response.status_code < 300:
            return pydantic_v1.parse_obj_as(MongoCollectionSyncResponse, _response.json())  # type: ignore
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def update_mongo_collection_sync(
        self,
        *,
        mongo_credential_id: uuid.UUID,
        mongo_uri: str,
        config: MongoCollectionSyncConfig,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> MongoCollectionSyncResponse:
        """
        Credal lets you easily sync your MongoDB data for use in Collections and Copilots. Update an existing sync from a MongoDB collection to a Credal collection via the `mongoCredentialId`, to disambiguate between multiple potential syncs to a given collection.

        Parameters
        ----------
        mongo_credential_id : uuid.UUID

        mongo_uri : str

        config : MongoCollectionSyncConfig

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

        Returns
        -------
        MongoCollectionSyncResponse

        Examples
        --------
        import uuid

        from credal import MongoCollectionSyncConfig, MongoSourceFieldsConfig
        from credal.client import AsyncCredalApi

        client = AsyncCredalApi(
            api_key="YOUR_API_KEY",
        )
        await client.document_collections.update_mongo_collection_sync(
            mongo_uri="mongodb+srv://cluster0.hzwklqn.mongodb.net/Cluster0?retryWrites=true&w=majority",
            mongo_credential_id=uuid.UUID(
                "5988ed76-6ee1-11ef-97dd-1fca54b7c4bc",
            ),
            config=MongoCollectionSyncConfig(
                sync_name="My recent summarized sales transcripts",
                collection_name="myCollection",
                filter_expression={
                    "transcriptDatetime": {"$gt": "2023-01-01T00:00:00.000Z"}
                },
                source_fields=MongoSourceFieldsConfig(
                    body="transcriptSummary",
                    source_name="meetingName",
                    source_system_updated="transcriptDatetime",
                    source_url="link",
                ),
            ),
        )
        """
        _response = await self._client_wrapper.httpx_client.request(
            method="POST",
            url=urllib.parse.urljoin(
                f"{self._client_wrapper.get_base_url()}/", "v0/documentCollections/mongodb/updateMongoSync"
            ),
            params=encode_query(
                jsonable_encoder(
                    request_options.get("additional_query_parameters") if request_options is not None else None
                )
            ),
            json=jsonable_encoder({"mongoCredentialId": mongo_credential_id, "mongoURI": mongo_uri, "config": config})
            if request_options is None or request_options.get("additional_body_parameters") is None
            else {
                **jsonable_encoder({"mongoCredentialId": mongo_credential_id, "mongoURI": mongo_uri, "config": config}),
                **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))),
            },
            headers=jsonable_encoder(
                remove_none_from_dict(
                    {
                        **self._client_wrapper.get_headers(),
                        **(request_options.get("additional_headers", {}) if request_options is not None else {}),
                    }
                )
            ),
            timeout=request_options.get("timeout_in_seconds")
            if request_options is not None and request_options.get("timeout_in_seconds") is not None
            else self._client_wrapper.get_timeout(),
            retries=0,
            max_retries=request_options.get("max_retries") if request_options is not None else 0,  # type: ignore
        )
        if 200 <= _response.status_code < 300:
            return pydantic_v1.parse_obj_as(MongoCollectionSyncResponse, _response.json())  # type: ignore
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)
