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

import typing
import uuid

from ..common.types.collaborator import Collaborator
from ..common.types.resource_identifier import ResourceIdentifier
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from .raw_client import AsyncRawDocumentCollectionsClient, RawDocumentCollectionsClient
from .types.create_collection_response import CreateCollectionResponse
from .types.delete_collection_response import DeleteCollectionResponse
from .types.list_documents_in_collection_response import ListDocumentsInCollectionResponse
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._raw_client = RawDocumentCollectionsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawDocumentCollectionsClient
        """
        return self._raw_client

    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 CredalApi
        from credal.common import ResourceIdentifier_ExternalResourceId

        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._raw_client.add_documents_to_collection(
            collection_id=collection_id, resource_identifiers=resource_identifiers, request_options=request_options
        )
        return _response.data

    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 CredalApi
        from credal.common import ResourceIdentifier_ExternalResourceId

        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._raw_client.remove_documents_from_collection(
            collection_id=collection_id, resource_identifiers=resource_identifiers, request_options=request_options
        )
        return _response.data

    def list_documents_in_collection(
        self, *, collection_id: uuid.UUID, request_options: typing.Optional[RequestOptions] = None
    ) -> ListDocumentsInCollectionResponse:
        """
        List documents in a collection

        Parameters
        ----------
        collection_id : uuid.UUID
            The ID of the document collection to list documents from.

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

        Returns
        -------
        ListDocumentsInCollectionResponse

        Examples
        --------
        import uuid

        from credal import CredalApi

        client = CredalApi(
            api_key="YOUR_API_KEY",
        )
        client.document_collections.list_documents_in_collection(
            collection_id=uuid.UUID(
                "82e4b12a-6990-45d4-8ebd-85c00e030c24",
            ),
        )
        """
        _response = self._raw_client.list_documents_in_collection(
            collection_id=collection_id, request_options=request_options
        )
        return _response.data

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

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

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

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

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

        Returns
        -------
        CreateCollectionResponse

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

        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._raw_client.create_collection(
            name=name, description=description, collaborators=collaborators, request_options=request_options
        )
        return _response.data

    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 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._raw_client.delete_collection(collection_id=collection_id, request_options=request_options)
        return _response.data

    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 Agents. 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 CredalApi
        from credal.document_collections import (
            MongoCollectionSyncConfig,
            MongoSourceFieldsConfig,
        )

        client = CredalApi(
            api_key="YOUR_API_KEY",
        )
        client.document_collections.create_mongo_collection_sync(
            mongo_uri="mongodb+srv://cluster0.abcdefg.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._raw_client.create_mongo_collection_sync(
            collection_id=collection_id, mongo_uri=mongo_uri, config=config, request_options=request_options
        )
        return _response.data

    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 Agents. 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 CredalApi
        from credal.document_collections import (
            MongoCollectionSyncConfig,
            MongoSourceFieldsConfig,
        )

        client = CredalApi(
            api_key="YOUR_API_KEY",
        )
        client.document_collections.update_mongo_collection_sync(
            mongo_uri="mongodb+srv://cluster0.abcdefg.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._raw_client.update_mongo_collection_sync(
            mongo_credential_id=mongo_credential_id, mongo_uri=mongo_uri, config=config, request_options=request_options
        )
        return _response.data


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

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

        Returns
        -------
        AsyncRawDocumentCollectionsClient
        """
        return self._raw_client

    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 asyncio
        import uuid

        from credal import AsyncCredalApi
        from credal.common import ResourceIdentifier_ExternalResourceId

        client = AsyncCredalApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            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",
                    ),
                ],
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.add_documents_to_collection(
            collection_id=collection_id, resource_identifiers=resource_identifiers, request_options=request_options
        )
        return _response.data

    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 asyncio
        import uuid

        from credal import AsyncCredalApi
        from credal.common import ResourceIdentifier_ExternalResourceId

        client = AsyncCredalApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            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",
                    ),
                ],
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.remove_documents_from_collection(
            collection_id=collection_id, resource_identifiers=resource_identifiers, request_options=request_options
        )
        return _response.data

    async def list_documents_in_collection(
        self, *, collection_id: uuid.UUID, request_options: typing.Optional[RequestOptions] = None
    ) -> ListDocumentsInCollectionResponse:
        """
        List documents in a collection

        Parameters
        ----------
        collection_id : uuid.UUID
            The ID of the document collection to list documents from.

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

        Returns
        -------
        ListDocumentsInCollectionResponse

        Examples
        --------
        import asyncio
        import uuid

        from credal import AsyncCredalApi

        client = AsyncCredalApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.document_collections.list_documents_in_collection(
                collection_id=uuid.UUID(
                    "82e4b12a-6990-45d4-8ebd-85c00e030c24",
                ),
            )


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

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

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

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

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

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

        Returns
        -------
        CreateCollectionResponse

        Examples
        --------
        import asyncio

        from credal import AsyncCredalApi
        from credal.common import Collaborator

        client = AsyncCredalApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            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",
                    )
                ],
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_collection(
            name=name, description=description, collaborators=collaborators, request_options=request_options
        )
        return _response.data

    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 asyncio
        import uuid

        from credal import AsyncCredalApi

        client = AsyncCredalApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.document_collections.delete_collection(
                collection_id=uuid.UUID(
                    "ac20e6ba-0bae-11ef-b25a-efca73df4c3a",
                ),
            )


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

    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 Agents. 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 asyncio
        import uuid

        from credal import AsyncCredalApi
        from credal.document_collections import (
            MongoCollectionSyncConfig,
            MongoSourceFieldsConfig,
        )

        client = AsyncCredalApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.document_collections.create_mongo_collection_sync(
                mongo_uri="mongodb+srv://cluster0.abcdefg.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",
                    ),
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_mongo_collection_sync(
            collection_id=collection_id, mongo_uri=mongo_uri, config=config, request_options=request_options
        )
        return _response.data

    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 Agents. 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 asyncio
        import uuid

        from credal import AsyncCredalApi
        from credal.document_collections import (
            MongoCollectionSyncConfig,
            MongoSourceFieldsConfig,
        )

        client = AsyncCredalApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.document_collections.update_mongo_collection_sync(
                mongo_uri="mongodb+srv://cluster0.abcdefg.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",
                    ),
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_mongo_collection_sync(
            mongo_credential_id=mongo_credential_id, mongo_uri=mongo_uri, config=config, request_options=request_options
        )
        return _response.data
