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

import typing

from .. import core
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.document import Document
from ..types.document_delete_response import DocumentDeleteResponse
from ..types.upload_response import UploadResponse
from .raw_client import AsyncRawUploadClient, RawUploadClient

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


class UploadClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawUploadClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawUploadClient
        """
        return self._raw_client

    def file(
        self, project_id: str, *, file: core.File, request_options: typing.Optional[RequestOptions] = None
    ) -> UploadResponse:
        """
        Upload a file for processing and indexing. Max 100MB.

        Parameters
        ----------
        project_id : str
            Project ID to upload the file to

        file : core.File
            See core.File for more documentation

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

        Returns
        -------
        UploadResponse
            File uploaded successfully

        Examples
        --------
        from tropicalia import tropicalia

        client = tropicalia(
            token="YOUR_TOKEN",
        )
        client.upload.file(
            project_id="projectId",
        )
        """
        _response = self._raw_client.file(project_id, file=file, request_options=request_options)
        return _response.data

    def list_documents(
        self,
        project_id: str,
        *,
        skip: typing.Optional[int] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[Document]:
        """
        List all documents in a project

        Parameters
        ----------
        project_id : str

        skip : typing.Optional[int]
            Number of documents to skip

        limit : typing.Optional[int]
            Maximum number of documents to return

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

        Returns
        -------
        typing.List[Document]
            List of documents

        Examples
        --------
        from tropicalia import tropicalia

        client = tropicalia(
            token="YOUR_TOKEN",
        )
        client.upload.list_documents(
            project_id="proj_9f8b7c6d5e4a3b2c1d0e",
        )
        """
        _response = self._raw_client.list_documents(project_id, skip=skip, limit=limit, request_options=request_options)
        return _response.data

    def delete_document(
        self, project_id: str, document_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DocumentDeleteResponse:
        """
        Delete a document from the project

        Parameters
        ----------
        project_id : str

        document_id : str

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

        Returns
        -------
        DocumentDeleteResponse
            Document deleted

        Examples
        --------
        from tropicalia import tropicalia

        client = tropicalia(
            token="YOUR_TOKEN",
        )
        client.upload.delete_document(
            project_id="proj_9f8b7c6d5e4a3b2c1d0e",
            document_id="3fa85f64-5717-4562-b3fc-2c963f66afa6",
        )
        """
        _response = self._raw_client.delete_document(project_id, document_id, request_options=request_options)
        return _response.data


class AsyncUploadClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawUploadClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawUploadClient
        """
        return self._raw_client

    async def file(
        self, project_id: str, *, file: core.File, request_options: typing.Optional[RequestOptions] = None
    ) -> UploadResponse:
        """
        Upload a file for processing and indexing. Max 100MB.

        Parameters
        ----------
        project_id : str
            Project ID to upload the file to

        file : core.File
            See core.File for more documentation

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

        Returns
        -------
        UploadResponse
            File uploaded successfully

        Examples
        --------
        import asyncio

        from tropicalia import Asynctropicalia

        client = Asynctropicalia(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.upload.file(
                project_id="projectId",
            )


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

    async def list_documents(
        self,
        project_id: str,
        *,
        skip: typing.Optional[int] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[Document]:
        """
        List all documents in a project

        Parameters
        ----------
        project_id : str

        skip : typing.Optional[int]
            Number of documents to skip

        limit : typing.Optional[int]
            Maximum number of documents to return

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

        Returns
        -------
        typing.List[Document]
            List of documents

        Examples
        --------
        import asyncio

        from tropicalia import Asynctropicalia

        client = Asynctropicalia(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.upload.list_documents(
                project_id="proj_9f8b7c6d5e4a3b2c1d0e",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list_documents(
            project_id, skip=skip, limit=limit, request_options=request_options
        )
        return _response.data

    async def delete_document(
        self, project_id: str, document_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DocumentDeleteResponse:
        """
        Delete a document from the project

        Parameters
        ----------
        project_id : str

        document_id : str

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

        Returns
        -------
        DocumentDeleteResponse
            Document deleted

        Examples
        --------
        import asyncio

        from tropicalia import Asynctropicalia

        client = Asynctropicalia(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.upload.delete_document(
                project_id="proj_9f8b7c6d5e4a3b2c1d0e",
                document_id="3fa85f64-5717-4562-b3fc-2c963f66afa6",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.delete_document(project_id, document_id, request_options=request_options)
        return _response.data
