# 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.instance_screenshot_response import InstanceScreenshotResponse
from ..core.jsonable_encoder import jsonable_encoder
from ..core.pydantic_utilities import parse_obj_as
from ..errors.unprocessable_entity_error import UnprocessableEntityError
from ..types.http_validation_error import HttpValidationError
from json.decoder import JSONDecodeError
from ..core.api_error import ApiError
from ..types.instance_get_stream_url_response import InstanceGetStreamUrlResponse
from .types.request import Request
from ..types.computer_response import ComputerResponse
from ..core.serialization import convert_and_respect_annotation_metadata
from ..types.bash_response import BashResponse
from .types.command import Command
from ..types.edit_response import EditResponse
from ..types.file_response import FileResponse
from ..types.stop_instance_response import StopInstanceResponse
from ..types.get_instance_response import GetInstanceResponse
from ..core.client_wrapper import AsyncClientWrapper

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


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

    def screenshot(
        self, instance_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> InstanceScreenshotResponse:
        """
        Parameters
        ----------
        instance_id : str

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

        Returns
        -------
        InstanceScreenshotResponse
            Successful Response

        Examples
        --------
        from scrapybara import Scrapybara

        client = Scrapybara(
            api_key="YOUR_API_KEY",
        )
        client.instance.screenshot(
            instance_id="instance_id",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/instance/{jsonable_encoder(instance_id)}/screenshot",
            method="POST",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    InstanceScreenshotResponse,
                    parse_obj_as(
                        type_=InstanceScreenshotResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    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, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def get_stream_url(
        self, instance_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> InstanceGetStreamUrlResponse:
        """
        Parameters
        ----------
        instance_id : str

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

        Returns
        -------
        InstanceGetStreamUrlResponse
            Successful Response

        Examples
        --------
        from scrapybara import Scrapybara

        client = Scrapybara(
            api_key="YOUR_API_KEY",
        )
        client.instance.get_stream_url(
            instance_id="instance_id",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/instance/{jsonable_encoder(instance_id)}/stream_url",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    InstanceGetStreamUrlResponse,
                    parse_obj_as(
                        type_=InstanceGetStreamUrlResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    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, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def computer(
        self, instance_id: str, *, request: Request, request_options: typing.Optional[RequestOptions] = None
    ) -> ComputerResponse:
        """
        Parameters
        ----------
        instance_id : str

        request : Request

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

        Returns
        -------
        ComputerResponse
            Successful Response

        Examples
        --------
        from scrapybara import Scrapybara
        from scrapybara.instance import Request_MoveMouse

        client = Scrapybara(
            api_key="YOUR_API_KEY",
        )
        client.instance.computer(
            instance_id="instance_id",
            request=Request_MoveMouse(
                coordinates=[1],
            ),
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/instance/{jsonable_encoder(instance_id)}/computer",
            method="POST",
            json=convert_and_respect_annotation_metadata(object_=request, annotation=Request, direction="write"),
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    ComputerResponse,
                    parse_obj_as(
                        type_=ComputerResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    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, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def bash(
        self,
        instance_id: str,
        *,
        command: typing.Optional[str] = OMIT,
        restart: typing.Optional[bool] = OMIT,
        get_background_processes: typing.Optional[bool] = OMIT,
        kill_pid: typing.Optional[int] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> BashResponse:
        """
        Parameters
        ----------
        instance_id : str

        command : typing.Optional[str]

        restart : typing.Optional[bool]

        get_background_processes : typing.Optional[bool]

        kill_pid : typing.Optional[int]

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

        Returns
        -------
        BashResponse
            Successful Response

        Examples
        --------
        from scrapybara import Scrapybara

        client = Scrapybara(
            api_key="YOUR_API_KEY",
        )
        client.instance.bash(
            instance_id="instance_id",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/instance/{jsonable_encoder(instance_id)}/bash",
            method="POST",
            json={
                "command": command,
                "restart": restart,
                "get_background_processes": get_background_processes,
                "kill_pid": kill_pid,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    BashResponse,
                    parse_obj_as(
                        type_=BashResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    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, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def edit(
        self,
        instance_id: str,
        *,
        command: Command,
        path: str,
        file_text: typing.Optional[str] = OMIT,
        view_range: typing.Optional[typing.Sequence[int]] = OMIT,
        old_str: typing.Optional[str] = OMIT,
        new_str: typing.Optional[str] = OMIT,
        insert_line: typing.Optional[int] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EditResponse:
        """
        Parameters
        ----------
        instance_id : str

        command : Command

        path : str

        file_text : typing.Optional[str]

        view_range : typing.Optional[typing.Sequence[int]]

        old_str : typing.Optional[str]

        new_str : typing.Optional[str]

        insert_line : typing.Optional[int]

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

        Returns
        -------
        EditResponse
            Successful Response

        Examples
        --------
        from scrapybara import Scrapybara

        client = Scrapybara(
            api_key="YOUR_API_KEY",
        )
        client.instance.edit(
            instance_id="instance_id",
            command="view",
            path="path",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/instance/{jsonable_encoder(instance_id)}/edit",
            method="POST",
            json={
                "command": command,
                "path": path,
                "file_text": file_text,
                "view_range": view_range,
                "old_str": old_str,
                "new_str": new_str,
                "insert_line": insert_line,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    EditResponse,
                    parse_obj_as(
                        type_=EditResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    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, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def file(
        self,
        instance_id: str,
        *,
        command: str,
        path: typing.Optional[str] = OMIT,
        content: typing.Optional[str] = OMIT,
        mode: typing.Optional[str] = OMIT,
        encoding: typing.Optional[str] = OMIT,
        view_range: typing.Optional[typing.Sequence[int]] = OMIT,
        recursive: typing.Optional[bool] = OMIT,
        src: typing.Optional[str] = OMIT,
        dst: typing.Optional[str] = OMIT,
        old_str: typing.Optional[str] = OMIT,
        new_str: typing.Optional[str] = OMIT,
        line: typing.Optional[int] = OMIT,
        text: typing.Optional[str] = OMIT,
        lines: typing.Optional[typing.Sequence[int]] = OMIT,
        all_occurrences: typing.Optional[bool] = OMIT,
        pattern: typing.Optional[str] = OMIT,
        case_sensitive: typing.Optional[bool] = OMIT,
        line_numbers: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> FileResponse:
        """
        Parameters
        ----------
        instance_id : str

        command : str

        path : typing.Optional[str]

        content : typing.Optional[str]

        mode : typing.Optional[str]

        encoding : typing.Optional[str]

        view_range : typing.Optional[typing.Sequence[int]]

        recursive : typing.Optional[bool]

        src : typing.Optional[str]

        dst : typing.Optional[str]

        old_str : typing.Optional[str]

        new_str : typing.Optional[str]

        line : typing.Optional[int]

        text : typing.Optional[str]

        lines : typing.Optional[typing.Sequence[int]]

        all_occurrences : typing.Optional[bool]

        pattern : typing.Optional[str]

        case_sensitive : typing.Optional[bool]

        line_numbers : typing.Optional[bool]

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

        Returns
        -------
        FileResponse
            Successful Response

        Examples
        --------
        from scrapybara import Scrapybara

        client = Scrapybara(
            api_key="YOUR_API_KEY",
        )
        client.instance.file(
            instance_id="instance_id",
            command="command",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/instance/{jsonable_encoder(instance_id)}/file",
            method="POST",
            json={
                "command": command,
                "path": path,
                "content": content,
                "mode": mode,
                "encoding": encoding,
                "view_range": view_range,
                "recursive": recursive,
                "src": src,
                "dst": dst,
                "old_str": old_str,
                "new_str": new_str,
                "line": line,
                "text": text,
                "lines": lines,
                "all_occurrences": all_occurrences,
                "pattern": pattern,
                "case_sensitive": case_sensitive,
                "line_numbers": line_numbers,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    FileResponse,
                    parse_obj_as(
                        type_=FileResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    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, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def stop(
        self, instance_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> StopInstanceResponse:
        """
        Parameters
        ----------
        instance_id : str

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

        Returns
        -------
        StopInstanceResponse
            Successful Response

        Examples
        --------
        from scrapybara import Scrapybara

        client = Scrapybara(
            api_key="YOUR_API_KEY",
        )
        client.instance.stop(
            instance_id="instance_id",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/instance/{jsonable_encoder(instance_id)}/stop",
            method="POST",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    StopInstanceResponse,
                    parse_obj_as(
                        type_=StopInstanceResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    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, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def pause(
        self, instance_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> StopInstanceResponse:
        """
        Parameters
        ----------
        instance_id : str

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

        Returns
        -------
        StopInstanceResponse
            Successful Response

        Examples
        --------
        from scrapybara import Scrapybara

        client = Scrapybara(
            api_key="YOUR_API_KEY",
        )
        client.instance.pause(
            instance_id="instance_id",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/instance/{jsonable_encoder(instance_id)}/pause",
            method="POST",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    StopInstanceResponse,
                    parse_obj_as(
                        type_=StopInstanceResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    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, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def resume(
        self,
        instance_id: str,
        *,
        timeout_hours: typing.Optional[float] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GetInstanceResponse:
        """
        Parameters
        ----------
        instance_id : str

        timeout_hours : typing.Optional[float]

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

        Returns
        -------
        GetInstanceResponse
            Successful Response

        Examples
        --------
        from scrapybara import Scrapybara

        client = Scrapybara(
            api_key="YOUR_API_KEY",
        )
        client.instance.resume(
            instance_id="instance_id",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/instance/{jsonable_encoder(instance_id)}/resume",
            method="POST",
            params={
                "timeout_hours": timeout_hours,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    GetInstanceResponse,
                    parse_obj_as(
                        type_=GetInstanceResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    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, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)


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

    async def screenshot(
        self, instance_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> InstanceScreenshotResponse:
        """
        Parameters
        ----------
        instance_id : str

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

        Returns
        -------
        InstanceScreenshotResponse
            Successful Response

        Examples
        --------
        import asyncio

        from scrapybara import AsyncScrapybara

        client = AsyncScrapybara(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.instance.screenshot(
                instance_id="instance_id",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/instance/{jsonable_encoder(instance_id)}/screenshot",
            method="POST",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    InstanceScreenshotResponse,
                    parse_obj_as(
                        type_=InstanceScreenshotResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    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, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def get_stream_url(
        self, instance_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> InstanceGetStreamUrlResponse:
        """
        Parameters
        ----------
        instance_id : str

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

        Returns
        -------
        InstanceGetStreamUrlResponse
            Successful Response

        Examples
        --------
        import asyncio

        from scrapybara import AsyncScrapybara

        client = AsyncScrapybara(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.instance.get_stream_url(
                instance_id="instance_id",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/instance/{jsonable_encoder(instance_id)}/stream_url",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    InstanceGetStreamUrlResponse,
                    parse_obj_as(
                        type_=InstanceGetStreamUrlResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    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, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def computer(
        self, instance_id: str, *, request: Request, request_options: typing.Optional[RequestOptions] = None
    ) -> ComputerResponse:
        """
        Parameters
        ----------
        instance_id : str

        request : Request

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

        Returns
        -------
        ComputerResponse
            Successful Response

        Examples
        --------
        import asyncio

        from scrapybara import AsyncScrapybara
        from scrapybara.instance import Request_MoveMouse

        client = AsyncScrapybara(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.instance.computer(
                instance_id="instance_id",
                request=Request_MoveMouse(
                    coordinates=[1],
                ),
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/instance/{jsonable_encoder(instance_id)}/computer",
            method="POST",
            json=convert_and_respect_annotation_metadata(object_=request, annotation=Request, direction="write"),
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    ComputerResponse,
                    parse_obj_as(
                        type_=ComputerResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    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, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def bash(
        self,
        instance_id: str,
        *,
        command: typing.Optional[str] = OMIT,
        restart: typing.Optional[bool] = OMIT,
        get_background_processes: typing.Optional[bool] = OMIT,
        kill_pid: typing.Optional[int] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> BashResponse:
        """
        Parameters
        ----------
        instance_id : str

        command : typing.Optional[str]

        restart : typing.Optional[bool]

        get_background_processes : typing.Optional[bool]

        kill_pid : typing.Optional[int]

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

        Returns
        -------
        BashResponse
            Successful Response

        Examples
        --------
        import asyncio

        from scrapybara import AsyncScrapybara

        client = AsyncScrapybara(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.instance.bash(
                instance_id="instance_id",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/instance/{jsonable_encoder(instance_id)}/bash",
            method="POST",
            json={
                "command": command,
                "restart": restart,
                "get_background_processes": get_background_processes,
                "kill_pid": kill_pid,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    BashResponse,
                    parse_obj_as(
                        type_=BashResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    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, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def edit(
        self,
        instance_id: str,
        *,
        command: Command,
        path: str,
        file_text: typing.Optional[str] = OMIT,
        view_range: typing.Optional[typing.Sequence[int]] = OMIT,
        old_str: typing.Optional[str] = OMIT,
        new_str: typing.Optional[str] = OMIT,
        insert_line: typing.Optional[int] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EditResponse:
        """
        Parameters
        ----------
        instance_id : str

        command : Command

        path : str

        file_text : typing.Optional[str]

        view_range : typing.Optional[typing.Sequence[int]]

        old_str : typing.Optional[str]

        new_str : typing.Optional[str]

        insert_line : typing.Optional[int]

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

        Returns
        -------
        EditResponse
            Successful Response

        Examples
        --------
        import asyncio

        from scrapybara import AsyncScrapybara

        client = AsyncScrapybara(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.instance.edit(
                instance_id="instance_id",
                command="view",
                path="path",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/instance/{jsonable_encoder(instance_id)}/edit",
            method="POST",
            json={
                "command": command,
                "path": path,
                "file_text": file_text,
                "view_range": view_range,
                "old_str": old_str,
                "new_str": new_str,
                "insert_line": insert_line,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    EditResponse,
                    parse_obj_as(
                        type_=EditResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    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, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def file(
        self,
        instance_id: str,
        *,
        command: str,
        path: typing.Optional[str] = OMIT,
        content: typing.Optional[str] = OMIT,
        mode: typing.Optional[str] = OMIT,
        encoding: typing.Optional[str] = OMIT,
        view_range: typing.Optional[typing.Sequence[int]] = OMIT,
        recursive: typing.Optional[bool] = OMIT,
        src: typing.Optional[str] = OMIT,
        dst: typing.Optional[str] = OMIT,
        old_str: typing.Optional[str] = OMIT,
        new_str: typing.Optional[str] = OMIT,
        line: typing.Optional[int] = OMIT,
        text: typing.Optional[str] = OMIT,
        lines: typing.Optional[typing.Sequence[int]] = OMIT,
        all_occurrences: typing.Optional[bool] = OMIT,
        pattern: typing.Optional[str] = OMIT,
        case_sensitive: typing.Optional[bool] = OMIT,
        line_numbers: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> FileResponse:
        """
        Parameters
        ----------
        instance_id : str

        command : str

        path : typing.Optional[str]

        content : typing.Optional[str]

        mode : typing.Optional[str]

        encoding : typing.Optional[str]

        view_range : typing.Optional[typing.Sequence[int]]

        recursive : typing.Optional[bool]

        src : typing.Optional[str]

        dst : typing.Optional[str]

        old_str : typing.Optional[str]

        new_str : typing.Optional[str]

        line : typing.Optional[int]

        text : typing.Optional[str]

        lines : typing.Optional[typing.Sequence[int]]

        all_occurrences : typing.Optional[bool]

        pattern : typing.Optional[str]

        case_sensitive : typing.Optional[bool]

        line_numbers : typing.Optional[bool]

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

        Returns
        -------
        FileResponse
            Successful Response

        Examples
        --------
        import asyncio

        from scrapybara import AsyncScrapybara

        client = AsyncScrapybara(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.instance.file(
                instance_id="instance_id",
                command="command",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/instance/{jsonable_encoder(instance_id)}/file",
            method="POST",
            json={
                "command": command,
                "path": path,
                "content": content,
                "mode": mode,
                "encoding": encoding,
                "view_range": view_range,
                "recursive": recursive,
                "src": src,
                "dst": dst,
                "old_str": old_str,
                "new_str": new_str,
                "line": line,
                "text": text,
                "lines": lines,
                "all_occurrences": all_occurrences,
                "pattern": pattern,
                "case_sensitive": case_sensitive,
                "line_numbers": line_numbers,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    FileResponse,
                    parse_obj_as(
                        type_=FileResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    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, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def stop(
        self, instance_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> StopInstanceResponse:
        """
        Parameters
        ----------
        instance_id : str

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

        Returns
        -------
        StopInstanceResponse
            Successful Response

        Examples
        --------
        import asyncio

        from scrapybara import AsyncScrapybara

        client = AsyncScrapybara(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.instance.stop(
                instance_id="instance_id",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/instance/{jsonable_encoder(instance_id)}/stop",
            method="POST",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    StopInstanceResponse,
                    parse_obj_as(
                        type_=StopInstanceResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    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, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def pause(
        self, instance_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> StopInstanceResponse:
        """
        Parameters
        ----------
        instance_id : str

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

        Returns
        -------
        StopInstanceResponse
            Successful Response

        Examples
        --------
        import asyncio

        from scrapybara import AsyncScrapybara

        client = AsyncScrapybara(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.instance.pause(
                instance_id="instance_id",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/instance/{jsonable_encoder(instance_id)}/pause",
            method="POST",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    StopInstanceResponse,
                    parse_obj_as(
                        type_=StopInstanceResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    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, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def resume(
        self,
        instance_id: str,
        *,
        timeout_hours: typing.Optional[float] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GetInstanceResponse:
        """
        Parameters
        ----------
        instance_id : str

        timeout_hours : typing.Optional[float]

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

        Returns
        -------
        GetInstanceResponse
            Successful Response

        Examples
        --------
        import asyncio

        from scrapybara import AsyncScrapybara

        client = AsyncScrapybara(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.instance.resume(
                instance_id="instance_id",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/instance/{jsonable_encoder(instance_id)}/resume",
            method="POST",
            params={
                "timeout_hours": timeout_hours,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    GetInstanceResponse,
                    parse_obj_as(
                        type_=GetInstanceResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    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, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)
