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

import typing
from json.decoder import JSONDecodeError

from ..core.api_error import ApiError
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.http_response import AsyncHttpResponse, HttpResponse
from ..core.jsonable_encoder import jsonable_encoder
from ..core.pydantic_utilities import parse_obj_as
from ..core.request_options import RequestOptions
from ..core.serialization import convert_and_respect_annotation_metadata
from ..errors.unprocessable_entity_error import UnprocessableEntityError
from ..types.filesystem_file import FilesystemFile
from ..types.filesystem_file_response import FilesystemFileResponse
from ..types.filesystem_response import FilesystemResponse
from ..types.http_validation_error import HttpValidationError
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

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


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

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

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

        Returns
        -------
        HttpResponse[typing.List[FilesystemResponse]]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "filesystems",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    typing.List[FilesystemResponse],
                    parse_obj_as(
                        type_=typing.List[FilesystemResponse],  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def create(
        self,
        *,
        project_id: str,
        name: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[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
        -------
        HttpResponse[FilesystemResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "filesystems",
            method="POST",
            json={
                "name": name,
                "project_id": project_id,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    FilesystemResponse,
                    parse_obj_as(
                        type_=FilesystemResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

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

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

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

        Returns
        -------
        HttpResponse[FilesystemResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"filesystems/{jsonable_encoder(filesystem_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    FilesystemResponse,
                    parse_obj_as(
                        type_=FilesystemResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def get_download_url(
        self,
        filesystem_id: str,
        *,
        request: typing.Optional[PresignedUrlRequest] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[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
        -------
        HttpResponse[PresignedUrlResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"filesystems/{jsonable_encoder(filesystem_id)}/download-url",
            method="POST",
            json=convert_and_respect_annotation_metadata(
                object_=request, annotation=typing.Optional[PresignedUrlRequest], direction="write"
            ),
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    PresignedUrlResponse,
                    parse_obj_as(
                        type_=PresignedUrlResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    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,
    ) -> HttpResponse[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
        -------
        HttpResponse[ListFilesResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"filesystems/{jsonable_encoder(filesystem_id)}/files",
            method="GET",
            params={
                "directory": directory,
                "recursive": recursive,
                "mime_type": mime_type,
                "include_content": include_content,
                "limit": limit,
                "offset": offset,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ListFilesResponse,
                    parse_obj_as(
                        type_=ListFilesResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def get_file(
        self,
        filesystem_id: str,
        file_path: str,
        *,
        include_content: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[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
        -------
        HttpResponse[FilesystemFileResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"filesystems/{jsonable_encoder(filesystem_id)}/files/{jsonable_encoder(file_path)}",
            method="GET",
            params={
                "include_content": include_content,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    FilesystemFileResponse,
                    parse_obj_as(
                        type_=FilesystemFileResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    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,
    ) -> HttpResponse[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
        -------
        HttpResponse[SyncCompleteResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"filesystems/{jsonable_encoder(filesystem_id)}/sync-complete",
            method="POST",
            json={
                "archive_checksum": archive_checksum,
                "archive_size_bytes": archive_size_bytes,
                "direction": direction,
                "files": convert_and_respect_annotation_metadata(
                    object_=files, annotation=typing.Optional[typing.Sequence[FilesystemFile]], direction="write"
                ),
                "status": status,
                "sync_id": sync_id,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SyncCompleteResponse,
                    parse_obj_as(
                        type_=SyncCompleteResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def get_upload_url(
        self,
        filesystem_id: str,
        *,
        request: typing.Optional[PresignedUrlRequest] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[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
        -------
        HttpResponse[PresignedUrlResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"filesystems/{jsonable_encoder(filesystem_id)}/upload-url",
            method="POST",
            json=convert_and_respect_annotation_metadata(
                object_=request, annotation=typing.Optional[PresignedUrlRequest], direction="write"
            ),
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    PresignedUrlResponse,
                    parse_obj_as(
                        type_=PresignedUrlResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)


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

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

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

        Returns
        -------
        AsyncHttpResponse[typing.List[FilesystemResponse]]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "filesystems",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    typing.List[FilesystemResponse],
                    parse_obj_as(
                        type_=typing.List[FilesystemResponse],  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def create(
        self,
        *,
        project_id: str,
        name: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[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
        -------
        AsyncHttpResponse[FilesystemResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "filesystems",
            method="POST",
            json={
                "name": name,
                "project_id": project_id,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    FilesystemResponse,
                    parse_obj_as(
                        type_=FilesystemResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

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

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

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

        Returns
        -------
        AsyncHttpResponse[FilesystemResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"filesystems/{jsonable_encoder(filesystem_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    FilesystemResponse,
                    parse_obj_as(
                        type_=FilesystemResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def get_download_url(
        self,
        filesystem_id: str,
        *,
        request: typing.Optional[PresignedUrlRequest] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[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
        -------
        AsyncHttpResponse[PresignedUrlResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"filesystems/{jsonable_encoder(filesystem_id)}/download-url",
            method="POST",
            json=convert_and_respect_annotation_metadata(
                object_=request, annotation=typing.Optional[PresignedUrlRequest], direction="write"
            ),
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    PresignedUrlResponse,
                    parse_obj_as(
                        type_=PresignedUrlResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    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,
    ) -> AsyncHttpResponse[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
        -------
        AsyncHttpResponse[ListFilesResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"filesystems/{jsonable_encoder(filesystem_id)}/files",
            method="GET",
            params={
                "directory": directory,
                "recursive": recursive,
                "mime_type": mime_type,
                "include_content": include_content,
                "limit": limit,
                "offset": offset,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ListFilesResponse,
                    parse_obj_as(
                        type_=ListFilesResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def get_file(
        self,
        filesystem_id: str,
        file_path: str,
        *,
        include_content: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[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
        -------
        AsyncHttpResponse[FilesystemFileResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"filesystems/{jsonable_encoder(filesystem_id)}/files/{jsonable_encoder(file_path)}",
            method="GET",
            params={
                "include_content": include_content,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    FilesystemFileResponse,
                    parse_obj_as(
                        type_=FilesystemFileResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    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,
    ) -> AsyncHttpResponse[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
        -------
        AsyncHttpResponse[SyncCompleteResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"filesystems/{jsonable_encoder(filesystem_id)}/sync-complete",
            method="POST",
            json={
                "archive_checksum": archive_checksum,
                "archive_size_bytes": archive_size_bytes,
                "direction": direction,
                "files": convert_and_respect_annotation_metadata(
                    object_=files, annotation=typing.Optional[typing.Sequence[FilesystemFile]], direction="write"
                ),
                "status": status,
                "sync_id": sync_id,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SyncCompleteResponse,
                    parse_obj_as(
                        type_=SyncCompleteResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def get_upload_url(
        self,
        filesystem_id: str,
        *,
        request: typing.Optional[PresignedUrlRequest] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[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
        -------
        AsyncHttpResponse[PresignedUrlResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"filesystems/{jsonable_encoder(filesystem_id)}/upload-url",
            method="POST",
            json=convert_and_respect_annotation_metadata(
                object_=request, annotation=typing.Optional[PresignedUrlRequest], direction="write"
            ),
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    PresignedUrlResponse,
                    parse_obj_as(
                        type_=PresignedUrlResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
