# 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.response import Response
from ..types.response_list import ResponseList
from ..types.route_response_model import RouteResponseModel
from .raw_client import AsyncRawBrowserNetworkClient, RawBrowserNetworkClient

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


class BrowserNetworkClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawBrowserNetworkClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawBrowserNetworkClient
        """
        return self._raw_client

    def set_headers(
        self, *, headers: typing.Dict[str, str], request_options: typing.Optional[RequestOptions] = None
    ) -> Response:
        """
        Set extra HTTP headers for all subsequent requests.

        Parameters
        ----------
        headers : typing.Dict[str, str]

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

        Returns
        -------
        Response
            Successful Response

        Examples
        --------
        from agent_sandbox import Sandbox

        client = Sandbox(
            base_url="https://yourhost.com/path/to/api",
        )
        client.browser_network.set_headers(
            headers={"key": "value"},
        )
        """
        _response = self._raw_client.set_headers(headers=headers, request_options=request_options)
        return _response.data

    def set_scoped_headers(
        self, *, origin: str, headers: typing.Dict[str, str], request_options: typing.Optional[RequestOptions] = None
    ) -> Response:
        """
        Set HTTP headers scoped to a specific origin.

        Parameters
        ----------
        origin : str

        headers : typing.Dict[str, str]

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

        Returns
        -------
        Response
            Successful Response

        Examples
        --------
        from agent_sandbox import Sandbox

        client = Sandbox(
            base_url="https://yourhost.com/path/to/api",
        )
        client.browser_network.set_scoped_headers(
            origin="origin",
            headers={"key": "value"},
        )
        """
        _response = self._raw_client.set_scoped_headers(origin=origin, headers=headers, request_options=request_options)
        return _response.data

    def add_route(
        self,
        *,
        url_pattern: str,
        response: typing.Optional[RouteResponseModel] = OMIT,
        abort: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Response:
        """
        Add a network route to mock or abort matching requests.

        Parameters
        ----------
        url_pattern : str

        response : typing.Optional[RouteResponseModel]

        abort : typing.Optional[bool]

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

        Returns
        -------
        Response
            Successful Response

        Examples
        --------
        from agent_sandbox import Sandbox

        client = Sandbox(
            base_url="https://yourhost.com/path/to/api",
        )
        client.browser_network.add_route(
            url_pattern="url_pattern",
        )
        """
        _response = self._raw_client.add_route(
            url_pattern=url_pattern, response=response, abort=abort, request_options=request_options
        )
        return _response.data

    def remove_route(self, *, url_pattern: str, request_options: typing.Optional[RequestOptions] = None) -> Response:
        """
        Remove a previously added network route.

        Parameters
        ----------
        url_pattern : str

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

        Returns
        -------
        Response
            Successful Response

        Examples
        --------
        from agent_sandbox import Sandbox

        client = Sandbox(
            base_url="https://yourhost.com/path/to/api",
        )
        client.browser_network.remove_route(
            url_pattern="url_pattern",
        )
        """
        _response = self._raw_client.remove_route(url_pattern=url_pattern, request_options=request_options)
        return _response.data

    def get_requests(
        self,
        *,
        filter: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ResponseList:
        """
        Get tracked network requests.

        Parameters
        ----------
        filter : typing.Optional[str]

        limit : typing.Optional[int]

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

        Returns
        -------
        ResponseList
            Successful Response

        Examples
        --------
        from agent_sandbox import Sandbox

        client = Sandbox(
            base_url="https://yourhost.com/path/to/api",
        )
        client.browser_network.get_requests(
            filter="filter",
            limit=1,
        )
        """
        _response = self._raw_client.get_requests(filter=filter, limit=limit, request_options=request_options)
        return _response.data

    def export_har(self, *, save_path: str, request_options: typing.Optional[RequestOptions] = None) -> Response:
        """
        Export tracked network requests as a HAR file.

        Parameters
        ----------
        save_path : str

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

        Returns
        -------
        Response
            Successful Response

        Examples
        --------
        from agent_sandbox import Sandbox

        client = Sandbox(
            base_url="https://yourhost.com/path/to/api",
        )
        client.browser_network.export_har(
            save_path="save_path",
        )
        """
        _response = self._raw_client.export_har(save_path=save_path, request_options=request_options)
        return _response.data


class AsyncBrowserNetworkClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawBrowserNetworkClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawBrowserNetworkClient
        """
        return self._raw_client

    async def set_headers(
        self, *, headers: typing.Dict[str, str], request_options: typing.Optional[RequestOptions] = None
    ) -> Response:
        """
        Set extra HTTP headers for all subsequent requests.

        Parameters
        ----------
        headers : typing.Dict[str, str]

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

        Returns
        -------
        Response
            Successful Response

        Examples
        --------
        import asyncio

        from agent_sandbox import AsyncSandbox

        client = AsyncSandbox(
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.browser_network.set_headers(
                headers={"key": "value"},
            )


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

    async def set_scoped_headers(
        self, *, origin: str, headers: typing.Dict[str, str], request_options: typing.Optional[RequestOptions] = None
    ) -> Response:
        """
        Set HTTP headers scoped to a specific origin.

        Parameters
        ----------
        origin : str

        headers : typing.Dict[str, str]

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

        Returns
        -------
        Response
            Successful Response

        Examples
        --------
        import asyncio

        from agent_sandbox import AsyncSandbox

        client = AsyncSandbox(
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.browser_network.set_scoped_headers(
                origin="origin",
                headers={"key": "value"},
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.set_scoped_headers(
            origin=origin, headers=headers, request_options=request_options
        )
        return _response.data

    async def add_route(
        self,
        *,
        url_pattern: str,
        response: typing.Optional[RouteResponseModel] = OMIT,
        abort: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Response:
        """
        Add a network route to mock or abort matching requests.

        Parameters
        ----------
        url_pattern : str

        response : typing.Optional[RouteResponseModel]

        abort : typing.Optional[bool]

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

        Returns
        -------
        Response
            Successful Response

        Examples
        --------
        import asyncio

        from agent_sandbox import AsyncSandbox

        client = AsyncSandbox(
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.browser_network.add_route(
                url_pattern="url_pattern",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.add_route(
            url_pattern=url_pattern, response=response, abort=abort, request_options=request_options
        )
        return _response.data

    async def remove_route(
        self, *, url_pattern: str, request_options: typing.Optional[RequestOptions] = None
    ) -> Response:
        """
        Remove a previously added network route.

        Parameters
        ----------
        url_pattern : str

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

        Returns
        -------
        Response
            Successful Response

        Examples
        --------
        import asyncio

        from agent_sandbox import AsyncSandbox

        client = AsyncSandbox(
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.browser_network.remove_route(
                url_pattern="url_pattern",
            )


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

    async def get_requests(
        self,
        *,
        filter: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ResponseList:
        """
        Get tracked network requests.

        Parameters
        ----------
        filter : typing.Optional[str]

        limit : typing.Optional[int]

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

        Returns
        -------
        ResponseList
            Successful Response

        Examples
        --------
        import asyncio

        from agent_sandbox import AsyncSandbox

        client = AsyncSandbox(
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.browser_network.get_requests(
                filter="filter",
                limit=1,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_requests(filter=filter, limit=limit, request_options=request_options)
        return _response.data

    async def export_har(self, *, save_path: str, request_options: typing.Optional[RequestOptions] = None) -> Response:
        """
        Export tracked network requests as a HAR file.

        Parameters
        ----------
        save_path : str

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

        Returns
        -------
        Response
            Successful Response

        Examples
        --------
        import asyncio

        from agent_sandbox import AsyncSandbox

        client = AsyncSandbox(
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.browser_network.export_har(
                save_path="save_path",
            )


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