# 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.src_app_http_routes_drive_sdk_drive_upload_response import SrcAppHttpRoutesDriveSdkDriveUploadResponse
from .raw_client import AsyncRawDriveClient, RawDriveClient

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


class DriveClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawDriveClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawDriveClient
        """
        return self._raw_client

    def upload(
        self,
        *,
        files: typing.List[core.File],
        metadata: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SrcAppHttpRoutesDriveSdkDriveUploadResponse:
        """
        Upload one or more files to Drive.

        - `files`: the file uploads (multipart)
        - `metadata`: a JSON string containing a list of per-file metadata dicts,
          positionally aligned with `files`. Each dict may contain:
            - `path`   — fully qualified destination path (takes precedence)
            - `folder` — destination folder
            - `name`   — destination filename

        Resolution logic for each file at index i:
        - If path is provided, use it as the fully qualified path
        - Else if folder and name are provided, combine as {folder}/{name}
        - Else if folder is provided, combine as {folder}/{upload_filename}
        - Else if name is provided, use /{name} (root)
        - Else fall back to None (domain default behavior)

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

        metadata : typing.Optional[str]

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

        Returns
        -------
        SrcAppHttpRoutesDriveSdkDriveUploadResponse
            Successful Response

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

        client = Scout(
            api_key="YOUR_API_KEY",
        )
        client.drive.upload()
        """
        _response = self._raw_client.upload(files=files, metadata=metadata, request_options=request_options)
        return _response.data

    def download(
        self,
        *,
        path: typing.Optional[str] = None,
        name: typing.Optional[str] = None,
        folder: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Iterator[bytes]:
        """
        Download a single file from Drive.

        Provide one of the following to identify the file:
        - `path`: fully qualified path (e.g., '/foo/bar/hello.txt')
        - `name` + `folder`: file name within a specific folder (e.g., name='hello.txt', folder='/foo/bar')

        Returns the file content as a streaming binary response.

        Parameters
        ----------
        path : typing.Optional[str]
            Fully qualified path to the file (e.g., '/foo/bar/hello.txt')

        name : typing.Optional[str]
            File name to search for (e.g., 'hello.txt')

        folder : typing.Optional[str]
            Folder to search within (e.g., '/foo/bar')

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response.

        Returns
        -------
        typing.Iterator[bytes]
            Successful Response

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

        client = Scout(
            api_key="YOUR_API_KEY",
        )
        client.drive.download()
        """
        with self._raw_client.download(path=path, name=name, folder=folder, request_options=request_options) as r:
            yield from r.data


class AsyncDriveClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawDriveClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawDriveClient
        """
        return self._raw_client

    async def upload(
        self,
        *,
        files: typing.List[core.File],
        metadata: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SrcAppHttpRoutesDriveSdkDriveUploadResponse:
        """
        Upload one or more files to Drive.

        - `files`: the file uploads (multipart)
        - `metadata`: a JSON string containing a list of per-file metadata dicts,
          positionally aligned with `files`. Each dict may contain:
            - `path`   — fully qualified destination path (takes precedence)
            - `folder` — destination folder
            - `name`   — destination filename

        Resolution logic for each file at index i:
        - If path is provided, use it as the fully qualified path
        - Else if folder and name are provided, combine as {folder}/{name}
        - Else if folder is provided, combine as {folder}/{upload_filename}
        - Else if name is provided, use /{name} (root)
        - Else fall back to None (domain default behavior)

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

        metadata : typing.Optional[str]

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

        Returns
        -------
        SrcAppHttpRoutesDriveSdkDriveUploadResponse
            Successful Response

        Examples
        --------
        import asyncio

        from scoutos import AsyncScout

        client = AsyncScout(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.drive.upload()


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

    async def download(
        self,
        *,
        path: typing.Optional[str] = None,
        name: typing.Optional[str] = None,
        folder: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.AsyncIterator[bytes]:
        """
        Download a single file from Drive.

        Provide one of the following to identify the file:
        - `path`: fully qualified path (e.g., '/foo/bar/hello.txt')
        - `name` + `folder`: file name within a specific folder (e.g., name='hello.txt', folder='/foo/bar')

        Returns the file content as a streaming binary response.

        Parameters
        ----------
        path : typing.Optional[str]
            Fully qualified path to the file (e.g., '/foo/bar/hello.txt')

        name : typing.Optional[str]
            File name to search for (e.g., 'hello.txt')

        folder : typing.Optional[str]
            Folder to search within (e.g., '/foo/bar')

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response.

        Returns
        -------
        typing.AsyncIterator[bytes]
            Successful Response

        Examples
        --------
        import asyncio

        from scoutos import AsyncScout

        client = AsyncScout(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.drive.download()


        asyncio.run(main())
        """
        async with self._raw_client.download(path=path, name=name, folder=folder, request_options=request_options) as r:
            async for _chunk in r.data:
                yield _chunk
