# 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.file_batch_upload_response import FileBatchUploadResponse
from ..types.file_content_response import FileContentResponse
from ..types.file_list_response import FileListResponse
from ..types.file_response import FileResponse
from .raw_client import AsyncRawFilesClient, RawFilesClient

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


class FilesClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawFilesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawFilesClient
        """
        return self._raw_client

    def upload_file(
        self,
        organization_id: str,
        *,
        files: typing.List[core.File],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> FileBatchUploadResponse:
        """
        Upload file(s) through backend.

        Accepts single or multiple file uploads (max 10) via multipart/form-data.
        Handles GCS upload internally. Works for files up to 100MB.

        Parameters
        ----------
        organization_id : str

        files : typing.List[core.File]
            See core.File for more documentation

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

        Returns
        -------
        FileBatchUploadResponse
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.files.upload_file(
            organization_id="organization_id",
        )
        """
        _response = self._raw_client.upload_file(organization_id, files=files, request_options=request_options)
        return _response.data

    def generate_upload_url(
        self,
        organization_id: str,
        *,
        request: typing.Dict[str, typing.Any],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Any:
        """
        Generate resumable upload URL(s) for file(s) (advanced).

        Requires 'files' array with 1-10 files. Always returns batch response format.

        Returns a resumable upload session URI valid for 7 days.
        Client uploads directly to GCS using the resumable protocol.
        Use this for large files (>32MB) or when you need resumable uploads.

        For simpler uploads, use POST /files/upload instead.

        Parameters
        ----------
        organization_id : str

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

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

        Returns
        -------
        typing.Any
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.files.generate_upload_url(
            organization_id="organization_id",
            request={"key": "value"},
        )
        """
        _response = self._raw_client.generate_upload_url(
            organization_id, request=request, request_options=request_options
        )
        return _response.data

    def list_files(
        self,
        organization_id: str,
        *,
        page: typing.Optional[int] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> FileListResponse:
        """
        List files for organization with pagination.

        Parameters
        ----------
        organization_id : str

        page : typing.Optional[int]

        limit : typing.Optional[int]

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

        Returns
        -------
        FileListResponse
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.files.list_files(
            organization_id="organization_id",
        )
        """
        _response = self._raw_client.list_files(
            organization_id, page=page, limit=limit, request_options=request_options
        )
        return _response.data

    def register_file(
        self,
        organization_id: str,
        *,
        request: typing.Dict[str, typing.Any],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Any:
        """
        Register completed file upload(s).

        Requires 'files' array with 1-10 files. Always returns batch response format.

        Call this endpoint after successfully uploading file(s) to GCS.
        This validates the upload and creates the database record(s).

        Parameters
        ----------
        organization_id : str

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

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

        Returns
        -------
        typing.Any
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.files.register_file(
            organization_id="organization_id",
            request={"key": "value"},
        )
        """
        _response = self._raw_client.register_file(organization_id, request=request, request_options=request_options)
        return _response.data

    def get_file(
        self, organization_id: str, file_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> FileResponse:
        """
        Get file details by ID.

        Parameters
        ----------
        organization_id : str

        file_id : str

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

        Returns
        -------
        FileResponse
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.files.get_file(
            organization_id="organization_id",
            file_id="file_id",
        )
        """
        _response = self._raw_client.get_file(organization_id, file_id, request_options=request_options)
        return _response.data

    def delete_file(
        self, organization_id: str, file_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Soft delete file.

        Removes file from database and all vector stores.
        Optionally removes from GCS storage.

        Parameters
        ----------
        organization_id : str

        file_id : str

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

        Returns
        -------
        None

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.files.delete_file(
            organization_id="organization_id",
            file_id="file_id",
        )
        """
        _response = self._raw_client.delete_file(organization_id, file_id, request_options=request_options)
        return _response.data

    def get_file_content(
        self, organization_id: str, file_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> FileContentResponse:
        """
        Get a signed download URL for file content.

        Parameters
        ----------
        organization_id : str

        file_id : str

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

        Returns
        -------
        FileContentResponse
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.files.get_file_content(
            organization_id="organization_id",
            file_id="file_id",
        )
        """
        _response = self._raw_client.get_file_content(organization_id, file_id, request_options=request_options)
        return _response.data

    def download_file_content(
        self,
        organization_id: str,
        file_id: str,
        *,
        token: str,
        expires: int,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Any:
        """
        Download file content. Auth via signed URL token (no bearer header needed).

        Parameters
        ----------
        organization_id : str

        file_id : str

        token : str
            Signed download token

        expires : int
            Token expiry timestamp

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

        Returns
        -------
        typing.Any
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.files.download_file_content(
            organization_id="organization_id",
            file_id="file_id",
            token="token",
            expires=1,
        )
        """
        _response = self._raw_client.download_file_content(
            organization_id, file_id, token=token, expires=expires, request_options=request_options
        )
        return _response.data


class AsyncFilesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawFilesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawFilesClient
        """
        return self._raw_client

    async def upload_file(
        self,
        organization_id: str,
        *,
        files: typing.List[core.File],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> FileBatchUploadResponse:
        """
        Upload file(s) through backend.

        Accepts single or multiple file uploads (max 10) via multipart/form-data.
        Handles GCS upload internally. Works for files up to 100MB.

        Parameters
        ----------
        organization_id : str

        files : typing.List[core.File]
            See core.File for more documentation

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

        Returns
        -------
        FileBatchUploadResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.files.upload_file(
                organization_id="organization_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.upload_file(organization_id, files=files, request_options=request_options)
        return _response.data

    async def generate_upload_url(
        self,
        organization_id: str,
        *,
        request: typing.Dict[str, typing.Any],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Any:
        """
        Generate resumable upload URL(s) for file(s) (advanced).

        Requires 'files' array with 1-10 files. Always returns batch response format.

        Returns a resumable upload session URI valid for 7 days.
        Client uploads directly to GCS using the resumable protocol.
        Use this for large files (>32MB) or when you need resumable uploads.

        For simpler uploads, use POST /files/upload instead.

        Parameters
        ----------
        organization_id : str

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

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

        Returns
        -------
        typing.Any
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.files.generate_upload_url(
                organization_id="organization_id",
                request={"key": "value"},
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.generate_upload_url(
            organization_id, request=request, request_options=request_options
        )
        return _response.data

    async def list_files(
        self,
        organization_id: str,
        *,
        page: typing.Optional[int] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> FileListResponse:
        """
        List files for organization with pagination.

        Parameters
        ----------
        organization_id : str

        page : typing.Optional[int]

        limit : typing.Optional[int]

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

        Returns
        -------
        FileListResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.files.list_files(
                organization_id="organization_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list_files(
            organization_id, page=page, limit=limit, request_options=request_options
        )
        return _response.data

    async def register_file(
        self,
        organization_id: str,
        *,
        request: typing.Dict[str, typing.Any],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Any:
        """
        Register completed file upload(s).

        Requires 'files' array with 1-10 files. Always returns batch response format.

        Call this endpoint after successfully uploading file(s) to GCS.
        This validates the upload and creates the database record(s).

        Parameters
        ----------
        organization_id : str

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

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

        Returns
        -------
        typing.Any
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.files.register_file(
                organization_id="organization_id",
                request={"key": "value"},
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.register_file(
            organization_id, request=request, request_options=request_options
        )
        return _response.data

    async def get_file(
        self, organization_id: str, file_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> FileResponse:
        """
        Get file details by ID.

        Parameters
        ----------
        organization_id : str

        file_id : str

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

        Returns
        -------
        FileResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.files.get_file(
                organization_id="organization_id",
                file_id="file_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_file(organization_id, file_id, request_options=request_options)
        return _response.data

    async def delete_file(
        self, organization_id: str, file_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Soft delete file.

        Removes file from database and all vector stores.
        Optionally removes from GCS storage.

        Parameters
        ----------
        organization_id : str

        file_id : str

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.files.delete_file(
                organization_id="organization_id",
                file_id="file_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.delete_file(organization_id, file_id, request_options=request_options)
        return _response.data

    async def get_file_content(
        self, organization_id: str, file_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> FileContentResponse:
        """
        Get a signed download URL for file content.

        Parameters
        ----------
        organization_id : str

        file_id : str

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

        Returns
        -------
        FileContentResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.files.get_file_content(
                organization_id="organization_id",
                file_id="file_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_file_content(organization_id, file_id, request_options=request_options)
        return _response.data

    async def download_file_content(
        self,
        organization_id: str,
        file_id: str,
        *,
        token: str,
        expires: int,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Any:
        """
        Download file content. Auth via signed URL token (no bearer header needed).

        Parameters
        ----------
        organization_id : str

        file_id : str

        token : str
            Signed download token

        expires : int
            Token expiry timestamp

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

        Returns
        -------
        typing.Any
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.files.download_file_content(
                organization_id="organization_id",
                file_id="file_id",
                token="token",
                expires=1,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.download_file_content(
            organization_id, file_id, token=token, expires=expires, request_options=request_options
        )
        return _response.data
