# 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.execute_response import ExecuteResponse
from ..types.sandbox_provider import SandboxProvider
from ..types.sandbox_response import SandboxResponse
from .raw_client import AsyncRawCodeInterpreterClient, RawCodeInterpreterClient

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


class CodeInterpreterClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawCodeInterpreterClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawCodeInterpreterClient
        """
        return self._raw_client

    def create(
        self,
        *,
        provider: typing.Optional[SandboxProvider] = OMIT,
        region: typing.Optional[str] = OMIT,
        timeout_minutes: typing.Optional[int] = OMIT,
        metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SandboxResponse:
        """
        Create a new code interpreter sandbox for executing Python code.

        Parameters
        ----------
        provider : typing.Optional[SandboxProvider]
            Provider to use (auto-detected if not specified)

        region : typing.Optional[str]
            Preferred region for the sandbox

        timeout_minutes : typing.Optional[int]
            Custom timeout in minutes

        metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
            Additional metadata

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

        Returns
        -------
        SandboxResponse
            Successful Response

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

        client = Sandbox(
            token="YOUR_TOKEN",
        )
        client.code_interpreter.create()
        """
        _response = self._raw_client.create(
            provider=provider,
            region=region,
            timeout_minutes=timeout_minutes,
            metadata=metadata,
            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 code interpreter 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.code_interpreter.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 AsyncCodeInterpreterClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawCodeInterpreterClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawCodeInterpreterClient
        """
        return self._raw_client

    async def create(
        self,
        *,
        provider: typing.Optional[SandboxProvider] = OMIT,
        region: typing.Optional[str] = OMIT,
        timeout_minutes: typing.Optional[int] = OMIT,
        metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SandboxResponse:
        """
        Create a new code interpreter sandbox for executing Python code.

        Parameters
        ----------
        provider : typing.Optional[SandboxProvider]
            Provider to use (auto-detected if not specified)

        region : typing.Optional[str]
            Preferred region for the sandbox

        timeout_minutes : typing.Optional[int]
            Custom timeout in minutes

        metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
            Additional metadata

        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.code_interpreter.create()


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            provider=provider,
            region=region,
            timeout_minutes=timeout_minutes,
            metadata=metadata,
            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 code interpreter 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.code_interpreter.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
