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

import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.filesystem_file import FilesystemFile
from ..types.filesystem_file_response import FilesystemFileResponse
from ..types.filesystem_response import FilesystemResponse
from ..types.list_files_response import ListFilesResponse
from ..types.presigned_url_request import PresignedUrlRequest
from ..types.presigned_url_response import PresignedUrlResponse
from ..types.sync_complete_response import SyncCompleteResponse
from .raw_client import AsyncRawFilesystemsClient, RawFilesystemsClient

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


class FilesystemsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawFilesystemsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawFilesystemsClient
        """
        return self._raw_client

    def list(
        self, *, project_id: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[FilesystemResponse]:
        """
        List all filesystems accessible to the current user.

        Parameters
        ----------
        project_id : typing.Optional[str]
            Optional project filter. When provided, requires read access to the project and returns only filesystems in that project.

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

        Returns
        -------
        typing.List[FilesystemResponse]
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.filesystems.list()
        """
        _response = self._raw_client.list(project_id=project_id, request_options=request_options)
        return _response.data

    def create(
        self,
        *,
        project_id: str,
        name: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> FilesystemResponse:
        """
        Create a new filesystem linked to a project.

        Parameters
        ----------
        project_id : str
            Project ID. Filesystem inherits permissions from the project.

        name : typing.Optional[str]
            Optional human-readable name for the filesystem (unique per namespace).

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

        Returns
        -------
        FilesystemResponse
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.filesystems.create(
            project_id="project_id",
        )
        """
        _response = self._raw_client.create(project_id=project_id, name=name, request_options=request_options)
        return _response.data

    def retrieve(
        self, filesystem_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> FilesystemResponse:
        """
        Get filesystem details by ID.

        Parameters
        ----------
        filesystem_id : str

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

        Returns
        -------
        FilesystemResponse
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.filesystems.retrieve(
            filesystem_id="filesystem_id",
        )
        """
        _response = self._raw_client.retrieve(filesystem_id, request_options=request_options)
        return _response.data

    def get_download_url(
        self,
        filesystem_id: str,
        *,
        request: typing.Optional[PresignedUrlRequest] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PresignedUrlResponse:
        """
        Get a presigned URL for direct download from GCS.

        Parameters
        ----------
        filesystem_id : str

        request : typing.Optional[PresignedUrlRequest]

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

        Returns
        -------
        PresignedUrlResponse
            Successful Response

        Examples
        --------
        from terminaluse import PresignedUrlRequest, TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.filesystems.get_download_url(
            filesystem_id="filesystem_id",
            request=PresignedUrlRequest(),
        )
        """
        _response = self._raw_client.get_download_url(filesystem_id, request=request, request_options=request_options)
        return _response.data

    def list_files(
        self,
        filesystem_id: str,
        *,
        directory: typing.Optional[str] = None,
        recursive: typing.Optional[bool] = None,
        mime_type: typing.Optional[str] = None,
        include_content: typing.Optional[bool] = None,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListFilesResponse:
        """
        List files in the filesystem manifest with optional filtering.

        Parameters
        ----------
        filesystem_id : str

        directory : typing.Optional[str]
            Directory prefix to filter results

        recursive : typing.Optional[bool]
            Include subdirectories

        mime_type : typing.Optional[str]
            Filter by MIME type

        include_content : typing.Optional[bool]
            Include file content in response

        limit : typing.Optional[int]
            Maximum number of results

        offset : typing.Optional[int]
            Pagination offset

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

        Returns
        -------
        ListFilesResponse
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.filesystems.list_files(
            filesystem_id="filesystem_id",
        )
        """
        _response = self._raw_client.list_files(
            filesystem_id,
            directory=directory,
            recursive=recursive,
            mime_type=mime_type,
            include_content=include_content,
            limit=limit,
            offset=offset,
            request_options=request_options,
        )
        return _response.data

    def get_file(
        self,
        filesystem_id: str,
        file_path: str,
        *,
        include_content: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> FilesystemFileResponse:
        """
        Retrieve a specific file (or directory) from the filesystem manifest.

        Parameters
        ----------
        filesystem_id : str

        file_path : str

        include_content : typing.Optional[bool]
            Include file content in response

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

        Returns
        -------
        FilesystemFileResponse
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.filesystems.get_file(
            filesystem_id="filesystem_id",
            file_path="file_path",
        )
        """
        _response = self._raw_client.get_file(
            filesystem_id, file_path, include_content=include_content, request_options=request_options
        )
        return _response.data

    def sync_complete(
        self,
        filesystem_id: str,
        *,
        direction: str,
        status: str,
        sync_id: str,
        archive_checksum: typing.Optional[str] = OMIT,
        archive_size_bytes: typing.Optional[int] = OMIT,
        files: typing.Optional[typing.Sequence[FilesystemFile]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SyncCompleteResponse:
        """
        Notify that a sync operation completed and provide the file manifest.

        Parameters
        ----------
        filesystem_id : str

        direction : str
            Sync direction: 'UP' or 'DOWN'.

        status : str
            Sync status: 'SUCCESS' or 'FAILED'.

        sync_id : str
            Unique ID for this sync operation (idempotency key).

        archive_checksum : typing.Optional[str]
            SHA256 checksum of the archive.

        archive_size_bytes : typing.Optional[int]
            Size of the archive in bytes.

        files : typing.Optional[typing.Sequence[FilesystemFile]]
            List of files in the filesystem (empty if status is FAILED).

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

        Returns
        -------
        SyncCompleteResponse
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.filesystems.sync_complete(
            filesystem_id="filesystem_id",
            direction="direction",
            status="status",
            sync_id="sync_id",
        )
        """
        _response = self._raw_client.sync_complete(
            filesystem_id,
            direction=direction,
            status=status,
            sync_id=sync_id,
            archive_checksum=archive_checksum,
            archive_size_bytes=archive_size_bytes,
            files=files,
            request_options=request_options,
        )
        return _response.data

    def get_upload_url(
        self,
        filesystem_id: str,
        *,
        request: typing.Optional[PresignedUrlRequest] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PresignedUrlResponse:
        """
        Get a presigned URL for direct upload to GCS.

        Parameters
        ----------
        filesystem_id : str

        request : typing.Optional[PresignedUrlRequest]

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

        Returns
        -------
        PresignedUrlResponse
            Successful Response

        Examples
        --------
        from terminaluse import PresignedUrlRequest, TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.filesystems.get_upload_url(
            filesystem_id="filesystem_id",
            request=PresignedUrlRequest(),
        )
        """
        _response = self._raw_client.get_upload_url(filesystem_id, request=request, request_options=request_options)
        return _response.data


class AsyncFilesystemsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawFilesystemsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawFilesystemsClient
        """
        return self._raw_client

    async def list(
        self, *, project_id: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[FilesystemResponse]:
        """
        List all filesystems accessible to the current user.

        Parameters
        ----------
        project_id : typing.Optional[str]
            Optional project filter. When provided, requires read access to the project and returns only filesystems in that project.

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

        Returns
        -------
        typing.List[FilesystemResponse]
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.filesystems.list()


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

    async def create(
        self,
        *,
        project_id: str,
        name: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> FilesystemResponse:
        """
        Create a new filesystem linked to a project.

        Parameters
        ----------
        project_id : str
            Project ID. Filesystem inherits permissions from the project.

        name : typing.Optional[str]
            Optional human-readable name for the filesystem (unique per namespace).

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

        Returns
        -------
        FilesystemResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.filesystems.create(
                project_id="project_id",
            )


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

    async def retrieve(
        self, filesystem_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> FilesystemResponse:
        """
        Get filesystem details by ID.

        Parameters
        ----------
        filesystem_id : str

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

        Returns
        -------
        FilesystemResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.filesystems.retrieve(
                filesystem_id="filesystem_id",
            )


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

    async def get_download_url(
        self,
        filesystem_id: str,
        *,
        request: typing.Optional[PresignedUrlRequest] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PresignedUrlResponse:
        """
        Get a presigned URL for direct download from GCS.

        Parameters
        ----------
        filesystem_id : str

        request : typing.Optional[PresignedUrlRequest]

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

        Returns
        -------
        PresignedUrlResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase, PresignedUrlRequest

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.filesystems.get_download_url(
                filesystem_id="filesystem_id",
                request=PresignedUrlRequest(),
            )


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

    async def list_files(
        self,
        filesystem_id: str,
        *,
        directory: typing.Optional[str] = None,
        recursive: typing.Optional[bool] = None,
        mime_type: typing.Optional[str] = None,
        include_content: typing.Optional[bool] = None,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListFilesResponse:
        """
        List files in the filesystem manifest with optional filtering.

        Parameters
        ----------
        filesystem_id : str

        directory : typing.Optional[str]
            Directory prefix to filter results

        recursive : typing.Optional[bool]
            Include subdirectories

        mime_type : typing.Optional[str]
            Filter by MIME type

        include_content : typing.Optional[bool]
            Include file content in response

        limit : typing.Optional[int]
            Maximum number of results

        offset : typing.Optional[int]
            Pagination offset

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

        Returns
        -------
        ListFilesResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


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


        asyncio.run(main())
        """
        _response = await self._raw_client.list_files(
            filesystem_id,
            directory=directory,
            recursive=recursive,
            mime_type=mime_type,
            include_content=include_content,
            limit=limit,
            offset=offset,
            request_options=request_options,
        )
        return _response.data

    async def get_file(
        self,
        filesystem_id: str,
        file_path: str,
        *,
        include_content: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> FilesystemFileResponse:
        """
        Retrieve a specific file (or directory) from the filesystem manifest.

        Parameters
        ----------
        filesystem_id : str

        file_path : str

        include_content : typing.Optional[bool]
            Include file content in response

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

        Returns
        -------
        FilesystemFileResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.filesystems.get_file(
                filesystem_id="filesystem_id",
                file_path="file_path",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_file(
            filesystem_id, file_path, include_content=include_content, request_options=request_options
        )
        return _response.data

    async def sync_complete(
        self,
        filesystem_id: str,
        *,
        direction: str,
        status: str,
        sync_id: str,
        archive_checksum: typing.Optional[str] = OMIT,
        archive_size_bytes: typing.Optional[int] = OMIT,
        files: typing.Optional[typing.Sequence[FilesystemFile]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SyncCompleteResponse:
        """
        Notify that a sync operation completed and provide the file manifest.

        Parameters
        ----------
        filesystem_id : str

        direction : str
            Sync direction: 'UP' or 'DOWN'.

        status : str
            Sync status: 'SUCCESS' or 'FAILED'.

        sync_id : str
            Unique ID for this sync operation (idempotency key).

        archive_checksum : typing.Optional[str]
            SHA256 checksum of the archive.

        archive_size_bytes : typing.Optional[int]
            Size of the archive in bytes.

        files : typing.Optional[typing.Sequence[FilesystemFile]]
            List of files in the filesystem (empty if status is FAILED).

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

        Returns
        -------
        SyncCompleteResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.filesystems.sync_complete(
                filesystem_id="filesystem_id",
                direction="direction",
                status="status",
                sync_id="sync_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.sync_complete(
            filesystem_id,
            direction=direction,
            status=status,
            sync_id=sync_id,
            archive_checksum=archive_checksum,
            archive_size_bytes=archive_size_bytes,
            files=files,
            request_options=request_options,
        )
        return _response.data

    async def get_upload_url(
        self,
        filesystem_id: str,
        *,
        request: typing.Optional[PresignedUrlRequest] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PresignedUrlResponse:
        """
        Get a presigned URL for direct upload to GCS.

        Parameters
        ----------
        filesystem_id : str

        request : typing.Optional[PresignedUrlRequest]

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

        Returns
        -------
        PresignedUrlResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase, PresignedUrlRequest

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.filesystems.get_upload_url(
                filesystem_id="filesystem_id",
                request=PresignedUrlRequest(),
            )


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