# 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.delete_response import DeleteResponse
from ..types.execute_response import ExecuteResponse
from ..types.sandbox_list_response import SandboxListResponse
from ..types.sandbox_response import SandboxResponse
from .raw_client import AsyncRawSandboxesClient, RawSandboxesClient

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


class SandboxesClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawSandboxesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawSandboxesClient
        """
        return self._raw_client

    def list(
        self, *, include_deleted: typing.Optional[bool] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> SandboxListResponse:
        """
        List all sandboxes for the authenticated user.

        Parameters
        ----------
        include_deleted : typing.Optional[bool]

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

        Returns
        -------
        SandboxListResponse
            Successful Response

        Examples
        --------
        from ai_infra import Sandbox

        client = Sandbox(
            token="YOUR_TOKEN",
        )
        client.sandboxes.list()
        """
        _response = self._raw_client.list(include_deleted=include_deleted, request_options=request_options)
        return _response.data

    def get(self, sandbox_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> SandboxResponse:
        """
        Get a specific sandbox by ID.

        Parameters
        ----------
        sandbox_id : str

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

        Returns
        -------
        SandboxResponse
            Successful Response

        Examples
        --------
        from ai_infra import Sandbox

        client = Sandbox(
            token="YOUR_TOKEN",
        )
        client.sandboxes.get(
            sandbox_id="sandbox_id",
        )
        """
        _response = self._raw_client.get(sandbox_id, request_options=request_options)
        return _response.data

    def delete(self, sandbox_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> DeleteResponse:
        """
        Delete a sandbox instance.

        Parameters
        ----------
        sandbox_id : str

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

        Returns
        -------
        DeleteResponse
            Successful Response

        Examples
        --------
        from ai_infra import Sandbox

        client = Sandbox(
            token="YOUR_TOKEN",
        )
        client.sandboxes.delete(
            sandbox_id="sandbox_id",
        )
        """
        _response = self._raw_client.delete(sandbox_id, request_options=request_options)
        return _response.data

    def execute(
        self,
        sandbox_id: str,
        *,
        command: str,
        timeout: typing.Optional[int] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ExecuteResponse:
        """
        Execute a command in a sandbox.

        Parameters
        ----------
        sandbox_id : str

        command : str
            Command or code to execute

        timeout : typing.Optional[int]
            Execution timeout in seconds

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

        Returns
        -------
        ExecuteResponse
            Successful Response

        Examples
        --------
        from ai_infra import Sandbox

        client = Sandbox(
            token="YOUR_TOKEN",
        )
        client.sandboxes.execute(
            sandbox_id="sandbox_id",
            command="command",
        )
        """
        _response = self._raw_client.execute(
            sandbox_id, command=command, timeout=timeout, request_options=request_options
        )
        return _response.data


class AsyncSandboxesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawSandboxesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawSandboxesClient
        """
        return self._raw_client

    async def list(
        self, *, include_deleted: typing.Optional[bool] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> SandboxListResponse:
        """
        List all sandboxes for the authenticated user.

        Parameters
        ----------
        include_deleted : typing.Optional[bool]

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

        Returns
        -------
        SandboxListResponse
            Successful Response

        Examples
        --------
        import asyncio

        from ai_infra import AsyncSandbox

        client = AsyncSandbox(
            token="YOUR_TOKEN",
        )


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


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

    async def get(self, sandbox_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> SandboxResponse:
        """
        Get a specific sandbox by ID.

        Parameters
        ----------
        sandbox_id : str

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

        Returns
        -------
        SandboxResponse
            Successful Response

        Examples
        --------
        import asyncio

        from ai_infra import AsyncSandbox

        client = AsyncSandbox(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.sandboxes.get(
                sandbox_id="sandbox_id",
            )


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

    async def delete(
        self, sandbox_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DeleteResponse:
        """
        Delete a sandbox instance.

        Parameters
        ----------
        sandbox_id : str

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

        Returns
        -------
        DeleteResponse
            Successful Response

        Examples
        --------
        import asyncio

        from ai_infra import AsyncSandbox

        client = AsyncSandbox(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.sandboxes.delete(
                sandbox_id="sandbox_id",
            )


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

    async def execute(
        self,
        sandbox_id: str,
        *,
        command: str,
        timeout: typing.Optional[int] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ExecuteResponse:
        """
        Execute a command in a sandbox.

        Parameters
        ----------
        sandbox_id : str

        command : str
            Command or code to execute

        timeout : typing.Optional[int]
            Execution timeout in seconds

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

        Returns
        -------
        ExecuteResponse
            Successful Response

        Examples
        --------
        import asyncio

        from ai_infra import AsyncSandbox

        client = AsyncSandbox(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.sandboxes.execute(
                sandbox_id="sandbox_id",
                command="command",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.execute(
            sandbox_id, command=command, timeout=timeout, request_options=request_options
        )
        return _response.data
