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

import typing
from ...core.client_wrapper import SyncClientWrapper
from ...core.request_options import RequestOptions
from ...types.gcs_export_storage import GcsExportStorage
from ...core.unchecked_base_model import construct_type
from json.decoder import JSONDecodeError
from ...core.api_error import ApiError
from ...core.jsonable_encoder import jsonable_encoder
from ...core.client_wrapper import AsyncClientWrapper

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


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

    def list(
        self,
        *,
        project: int,
        ordering: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[GcsExportStorage]:
        """
        Get a list of all GCS export storage connections.

        Parameters
        ----------
        project : int
            Project ID

        ordering : typing.Optional[str]
            Which field to use when ordering the results.

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

        Returns
        -------
        typing.List[GcsExportStorage]


        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.export_storage.gcs.list(
            project=1,
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            "api/storages/export/gcs",
            method="GET",
            params={
                "ordering": ordering,
                "project": project,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    typing.List[GcsExportStorage],
                    construct_type(
                        type_=typing.List[GcsExportStorage],  # type: ignore
                        object_=_response.json(),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def create(
        self,
        *,
        bucket: typing.Optional[str] = OMIT,
        can_delete_objects: typing.Optional[bool] = OMIT,
        description: typing.Optional[str] = OMIT,
        google_application_credentials: typing.Optional[str] = OMIT,
        google_project_id: typing.Optional[str] = OMIT,
        prefix: typing.Optional[str] = OMIT,
        project: typing.Optional[int] = OMIT,
        title: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GcsExportStorage:
        """
        Create a new GCS export storage connection to store annotations.

        Parameters
        ----------
        bucket : typing.Optional[str]
            GCS bucket name

        can_delete_objects : typing.Optional[bool]
            Deletion from storage enabled.

        description : typing.Optional[str]
            Storage description

        google_application_credentials : typing.Optional[str]
            The content of GOOGLE_APPLICATION_CREDENTIALS json file. Check official Google Cloud Authentication documentation for more details.

        google_project_id : typing.Optional[str]
            Google project ID

        prefix : typing.Optional[str]
            GCS bucket prefix

        project : typing.Optional[int]
            Project ID

        title : typing.Optional[str]
            Storage title

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

        Returns
        -------
        GcsExportStorage


        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.export_storage.gcs.create()
        """
        _response = self._client_wrapper.httpx_client.request(
            "api/storages/export/gcs",
            method="POST",
            json={
                "bucket": bucket,
                "can_delete_objects": can_delete_objects,
                "description": description,
                "google_application_credentials": google_application_credentials,
                "google_project_id": google_project_id,
                "prefix": prefix,
                "project": project,
                "title": title,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    GcsExportStorage,
                    construct_type(
                        type_=GcsExportStorage,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def validate(
        self,
        *,
        bucket: typing.Optional[str] = OMIT,
        can_delete_objects: typing.Optional[bool] = OMIT,
        description: typing.Optional[str] = OMIT,
        google_application_credentials: typing.Optional[str] = OMIT,
        google_project_id: typing.Optional[str] = OMIT,
        id: typing.Optional[int] = OMIT,
        prefix: typing.Optional[str] = OMIT,
        project: typing.Optional[int] = OMIT,
        title: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Validate a specific GCS export storage connection.

        Parameters
        ----------
        bucket : typing.Optional[str]
            GCS bucket name

        can_delete_objects : typing.Optional[bool]
            Deletion from storage enabled.

        description : typing.Optional[str]
            Storage description

        google_application_credentials : typing.Optional[str]
            The content of GOOGLE_APPLICATION_CREDENTIALS json file. Check official Google Cloud Authentication documentation for more details.

        google_project_id : typing.Optional[str]
            Google project ID

        id : typing.Optional[int]
            Storage ID. If set, storage with specified ID will be updated

        prefix : typing.Optional[str]
            GCS bucket prefix

        project : typing.Optional[int]
            Project ID

        title : typing.Optional[str]
            Storage title

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

        Returns
        -------
        None

        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.export_storage.gcs.validate()
        """
        _response = self._client_wrapper.httpx_client.request(
            "api/storages/export/gcs/validate",
            method="POST",
            json={
                "bucket": bucket,
                "can_delete_objects": can_delete_objects,
                "description": description,
                "google_application_credentials": google_application_credentials,
                "google_project_id": google_project_id,
                "id": id,
                "prefix": prefix,
                "project": project,
                "title": title,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def get(self, id: int, *, request_options: typing.Optional[RequestOptions] = None) -> GcsExportStorage:
        """
        Get a specific GCS export storage connection.

        Parameters
        ----------
        id : int

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

        Returns
        -------
        GcsExportStorage


        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.export_storage.gcs.get(
            id=1,
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/storages/export/gcs/{jsonable_encoder(id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    GcsExportStorage,
                    construct_type(
                        type_=GcsExportStorage,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def delete(self, id: int, *, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        Delete a specific GCS export storage connection.

        Parameters
        ----------
        id : int

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

        Returns
        -------
        None

        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.export_storage.gcs.delete(
            id=1,
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/storages/export/gcs/{jsonable_encoder(id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def update(
        self,
        id: int,
        *,
        bucket: typing.Optional[str] = OMIT,
        can_delete_objects: typing.Optional[bool] = OMIT,
        description: typing.Optional[str] = OMIT,
        google_application_credentials: typing.Optional[str] = OMIT,
        google_project_id: typing.Optional[str] = OMIT,
        prefix: typing.Optional[str] = OMIT,
        project: typing.Optional[int] = OMIT,
        title: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GcsExportStorage:
        """
        Update a specific GCS export storage connection.

        Parameters
        ----------
        id : int

        bucket : typing.Optional[str]
            GCS bucket name

        can_delete_objects : typing.Optional[bool]
            Deletion from storage enabled.

        description : typing.Optional[str]
            Storage description

        google_application_credentials : typing.Optional[str]
            The content of GOOGLE_APPLICATION_CREDENTIALS json file. Check official Google Cloud Authentication documentation for more details.

        google_project_id : typing.Optional[str]
            Google project ID

        prefix : typing.Optional[str]
            GCS bucket prefix

        project : typing.Optional[int]
            Project ID

        title : typing.Optional[str]
            Storage title

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

        Returns
        -------
        GcsExportStorage


        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.export_storage.gcs.update(
            id=1,
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/storages/export/gcs/{jsonable_encoder(id)}",
            method="PATCH",
            json={
                "bucket": bucket,
                "can_delete_objects": can_delete_objects,
                "description": description,
                "google_application_credentials": google_application_credentials,
                "google_project_id": google_project_id,
                "prefix": prefix,
                "project": project,
                "title": title,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    GcsExportStorage,
                    construct_type(
                        type_=GcsExportStorage,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def sync(self, id: int, *, request_options: typing.Optional[RequestOptions] = None) -> GcsExportStorage:
        """
        Sync tasks from an GCS export storage connection.

        Parameters
        ----------
        id : int

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

        Returns
        -------
        GcsExportStorage


        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.export_storage.gcs.sync(
            id=1,
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/storages/export/gcs/{jsonable_encoder(id)}/sync",
            method="POST",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    GcsExportStorage,
                    construct_type(
                        type_=GcsExportStorage,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)


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

    async def list(
        self,
        *,
        project: int,
        ordering: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[GcsExportStorage]:
        """
        Get a list of all GCS export storage connections.

        Parameters
        ----------
        project : int
            Project ID

        ordering : typing.Optional[str]
            Which field to use when ordering the results.

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

        Returns
        -------
        typing.List[GcsExportStorage]


        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.export_storage.gcs.list(
                project=1,
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/storages/export/gcs",
            method="GET",
            params={
                "ordering": ordering,
                "project": project,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    typing.List[GcsExportStorage],
                    construct_type(
                        type_=typing.List[GcsExportStorage],  # type: ignore
                        object_=_response.json(),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def create(
        self,
        *,
        bucket: typing.Optional[str] = OMIT,
        can_delete_objects: typing.Optional[bool] = OMIT,
        description: typing.Optional[str] = OMIT,
        google_application_credentials: typing.Optional[str] = OMIT,
        google_project_id: typing.Optional[str] = OMIT,
        prefix: typing.Optional[str] = OMIT,
        project: typing.Optional[int] = OMIT,
        title: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GcsExportStorage:
        """
        Create a new GCS export storage connection to store annotations.

        Parameters
        ----------
        bucket : typing.Optional[str]
            GCS bucket name

        can_delete_objects : typing.Optional[bool]
            Deletion from storage enabled.

        description : typing.Optional[str]
            Storage description

        google_application_credentials : typing.Optional[str]
            The content of GOOGLE_APPLICATION_CREDENTIALS json file. Check official Google Cloud Authentication documentation for more details.

        google_project_id : typing.Optional[str]
            Google project ID

        prefix : typing.Optional[str]
            GCS bucket prefix

        project : typing.Optional[int]
            Project ID

        title : typing.Optional[str]
            Storage title

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

        Returns
        -------
        GcsExportStorage


        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.export_storage.gcs.create()


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/storages/export/gcs",
            method="POST",
            json={
                "bucket": bucket,
                "can_delete_objects": can_delete_objects,
                "description": description,
                "google_application_credentials": google_application_credentials,
                "google_project_id": google_project_id,
                "prefix": prefix,
                "project": project,
                "title": title,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    GcsExportStorage,
                    construct_type(
                        type_=GcsExportStorage,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def validate(
        self,
        *,
        bucket: typing.Optional[str] = OMIT,
        can_delete_objects: typing.Optional[bool] = OMIT,
        description: typing.Optional[str] = OMIT,
        google_application_credentials: typing.Optional[str] = OMIT,
        google_project_id: typing.Optional[str] = OMIT,
        id: typing.Optional[int] = OMIT,
        prefix: typing.Optional[str] = OMIT,
        project: typing.Optional[int] = OMIT,
        title: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Validate a specific GCS export storage connection.

        Parameters
        ----------
        bucket : typing.Optional[str]
            GCS bucket name

        can_delete_objects : typing.Optional[bool]
            Deletion from storage enabled.

        description : typing.Optional[str]
            Storage description

        google_application_credentials : typing.Optional[str]
            The content of GOOGLE_APPLICATION_CREDENTIALS json file. Check official Google Cloud Authentication documentation for more details.

        google_project_id : typing.Optional[str]
            Google project ID

        id : typing.Optional[int]
            Storage ID. If set, storage with specified ID will be updated

        prefix : typing.Optional[str]
            GCS bucket prefix

        project : typing.Optional[int]
            Project ID

        title : typing.Optional[str]
            Storage title

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.export_storage.gcs.validate()


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/storages/export/gcs/validate",
            method="POST",
            json={
                "bucket": bucket,
                "can_delete_objects": can_delete_objects,
                "description": description,
                "google_application_credentials": google_application_credentials,
                "google_project_id": google_project_id,
                "id": id,
                "prefix": prefix,
                "project": project,
                "title": title,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def get(self, id: int, *, request_options: typing.Optional[RequestOptions] = None) -> GcsExportStorage:
        """
        Get a specific GCS export storage connection.

        Parameters
        ----------
        id : int

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

        Returns
        -------
        GcsExportStorage


        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.export_storage.gcs.get(
                id=1,
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/storages/export/gcs/{jsonable_encoder(id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    GcsExportStorage,
                    construct_type(
                        type_=GcsExportStorage,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def delete(self, id: int, *, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        Delete a specific GCS export storage connection.

        Parameters
        ----------
        id : int

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.export_storage.gcs.delete(
                id=1,
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/storages/export/gcs/{jsonable_encoder(id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def update(
        self,
        id: int,
        *,
        bucket: typing.Optional[str] = OMIT,
        can_delete_objects: typing.Optional[bool] = OMIT,
        description: typing.Optional[str] = OMIT,
        google_application_credentials: typing.Optional[str] = OMIT,
        google_project_id: typing.Optional[str] = OMIT,
        prefix: typing.Optional[str] = OMIT,
        project: typing.Optional[int] = OMIT,
        title: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GcsExportStorage:
        """
        Update a specific GCS export storage connection.

        Parameters
        ----------
        id : int

        bucket : typing.Optional[str]
            GCS bucket name

        can_delete_objects : typing.Optional[bool]
            Deletion from storage enabled.

        description : typing.Optional[str]
            Storage description

        google_application_credentials : typing.Optional[str]
            The content of GOOGLE_APPLICATION_CREDENTIALS json file. Check official Google Cloud Authentication documentation for more details.

        google_project_id : typing.Optional[str]
            Google project ID

        prefix : typing.Optional[str]
            GCS bucket prefix

        project : typing.Optional[int]
            Project ID

        title : typing.Optional[str]
            Storage title

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

        Returns
        -------
        GcsExportStorage


        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.export_storage.gcs.update(
                id=1,
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/storages/export/gcs/{jsonable_encoder(id)}",
            method="PATCH",
            json={
                "bucket": bucket,
                "can_delete_objects": can_delete_objects,
                "description": description,
                "google_application_credentials": google_application_credentials,
                "google_project_id": google_project_id,
                "prefix": prefix,
                "project": project,
                "title": title,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    GcsExportStorage,
                    construct_type(
                        type_=GcsExportStorage,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def sync(self, id: int, *, request_options: typing.Optional[RequestOptions] = None) -> GcsExportStorage:
        """
        Sync tasks from an GCS export storage connection.

        Parameters
        ----------
        id : int

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

        Returns
        -------
        GcsExportStorage


        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.export_storage.gcs.sync(
                id=1,
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/storages/export/gcs/{jsonable_encoder(id)}/sync",
            method="POST",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    GcsExportStorage,
                    construct_type(
                        type_=GcsExportStorage,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)
