# 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_proxy_mapping_route import ResponseListProxyMappingRoute
from ..types.response_list_str import ResponseListStr
from ..types.response_proxy_diagnose_result import ResponseProxyDiagnoseResult
from ..types.response_proxy_mapping_route import ResponseProxyMappingRoute
from ..types.response_proxy_upstream_info import ResponseProxyUpstreamInfo
from ..types.response_union_proxy_upstream_info_none_type import ResponseUnionProxyUpstreamInfoNoneType
from .raw_client import AsyncRawProxyClient, RawProxyClient

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


class ProxyClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawProxyClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawProxyClient
        """
        return self._raw_client

    def list_mappings(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ResponseListProxyMappingRoute:
        """
        List all proxy domain-to-port mappings.

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

        Returns
        -------
        ResponseListProxyMappingRoute
            Successful Response

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

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

    def add_mapping(
        self, *, source: str, target: str, request_options: typing.Optional[RequestOptions] = None
    ) -> ResponseProxyMappingRoute:
        """
        Add or update a proxy mapping. Supports wildcards in host (*.example.com).

        Parameters
        ----------
        source : str
            Source pattern: [protocol://]host[:port][/path], supports wildcard *

        target : str
            Target address: [host:]port[/path]. Host defaults to 127.0.0.1

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

        Returns
        -------
        ResponseProxyMappingRoute
            Successful Response

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

        client = Sandbox(
            base_url="https://yourhost.com/path/to/api",
        )
        client.proxy.add_mapping(
            source="myapp.com",
            target=":3000",
        )
        """
        _response = self._raw_client.add_mapping(source=source, target=target, request_options=request_options)
        return _response.data

    def remove_mapping(self, source: str, *, request_options: typing.Optional[RequestOptions] = None) -> Response:
        """
        Remove a proxy mapping by source pattern.

        Parameters
        ----------
        source : 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.proxy.remove_mapping(
            source="source",
        )
        """
        _response = self._raw_client.remove_mapping(source, request_options=request_options)
        return _response.data

    def list_excludes(self, *, request_options: typing.Optional[RequestOptions] = None) -> ResponseListStr:
        """
        List all proxy bypass/exclude patterns.

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

        Returns
        -------
        ResponseListStr
            Successful Response

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

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

    def add_exclude(self, *, pattern: str, request_options: typing.Optional[RequestOptions] = None) -> Response:
        """
        Add a bypass/exclude pattern. Matched domains connect directly.

        Parameters
        ----------
        pattern : str
            Bypass pattern: domain (*.example.com, .example.com) or CIDR (10.0.0.0/8)

        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.proxy.add_exclude(
            pattern="*.internal.company.com",
        )
        """
        _response = self._raw_client.add_exclude(pattern=pattern, request_options=request_options)
        return _response.data

    def remove_exclude(self, *, pattern: str, request_options: typing.Optional[RequestOptions] = None) -> Response:
        """
        Remove a bypass/exclude pattern.

        Parameters
        ----------
        pattern : str
            Bypass pattern: domain (*.example.com, .example.com) or CIDR (10.0.0.0/8)

        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.proxy.remove_exclude(
            pattern="*.internal.company.com",
        )
        """
        _response = self._raw_client.remove_exclude(pattern=pattern, request_options=request_options)
        return _response.data

    def diagnose(
        self, *, url: str, request_options: typing.Optional[RequestOptions] = None
    ) -> ResponseProxyDiagnoseResult:
        """
        Diagnose how a URL would be routed through the proxy.

        Parameters
        ----------
        url : str
            URL to diagnose routing for

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

        Returns
        -------
        ResponseProxyDiagnoseResult
            Successful Response

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

        client = Sandbox(
            base_url="https://yourhost.com/path/to/api",
        )
        client.proxy.diagnose(
            url="url",
        )
        """
        _response = self._raw_client.diagnose(url=url, request_options=request_options)
        return _response.data

    def get_upstream(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ResponseUnionProxyUpstreamInfoNoneType:
        """
        Get the current upstream proxy configuration.

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

        Returns
        -------
        ResponseUnionProxyUpstreamInfoNoneType
            Successful Response

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

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

    def set_upstream(
        self,
        *,
        server: str,
        auth_cmd: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ResponseProxyUpstreamInfo:
        """
        Set or update the upstream proxy. Supports user:pass@host:port format.

        Takes effect immediately — no browser restart needed.

        Parameters
        ----------
        server : str
            Upstream proxy server. Supports plain host:port or user:pass@host:port

        auth_cmd : typing.Optional[str]
            Optional shell command to obtain proxy credentials. The command stdout should be "username:password". When set, the result is injected into the server URL, replacing any inline credentials.

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

        Returns
        -------
        ResponseProxyUpstreamInfo
            Successful Response

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

        client = Sandbox(
            base_url="https://yourhost.com/path/to/api",
        )
        client.proxy.set_upstream(
            server="proxy.example.com:3128",
        )
        """
        _response = self._raw_client.set_upstream(server=server, auth_cmd=auth_cmd, request_options=request_options)
        return _response.data

    def remove_upstream(self, *, request_options: typing.Optional[RequestOptions] = None) -> Response:
        """
        Remove upstream proxy (switch to direct mode).

        Parameters
        ----------
        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.proxy.remove_upstream()
        """
        _response = self._raw_client.remove_upstream(request_options=request_options)
        return _response.data


class AsyncProxyClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawProxyClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawProxyClient
        """
        return self._raw_client

    async def list_mappings(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ResponseListProxyMappingRoute:
        """
        List all proxy domain-to-port mappings.

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

        Returns
        -------
        ResponseListProxyMappingRoute
            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.proxy.list_mappings()


        asyncio.run(main())
        """
        _response = await self._raw_client.list_mappings(request_options=request_options)
        return _response.data

    async def add_mapping(
        self, *, source: str, target: str, request_options: typing.Optional[RequestOptions] = None
    ) -> ResponseProxyMappingRoute:
        """
        Add or update a proxy mapping. Supports wildcards in host (*.example.com).

        Parameters
        ----------
        source : str
            Source pattern: [protocol://]host[:port][/path], supports wildcard *

        target : str
            Target address: [host:]port[/path]. Host defaults to 127.0.0.1

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

        Returns
        -------
        ResponseProxyMappingRoute
            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.proxy.add_mapping(
                source="myapp.com",
                target=":3000",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.add_mapping(source=source, target=target, request_options=request_options)
        return _response.data

    async def remove_mapping(self, source: str, *, request_options: typing.Optional[RequestOptions] = None) -> Response:
        """
        Remove a proxy mapping by source pattern.

        Parameters
        ----------
        source : 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.proxy.remove_mapping(
                source="source",
            )


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

    async def list_excludes(self, *, request_options: typing.Optional[RequestOptions] = None) -> ResponseListStr:
        """
        List all proxy bypass/exclude patterns.

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

        Returns
        -------
        ResponseListStr
            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.proxy.list_excludes()


        asyncio.run(main())
        """
        _response = await self._raw_client.list_excludes(request_options=request_options)
        return _response.data

    async def add_exclude(self, *, pattern: str, request_options: typing.Optional[RequestOptions] = None) -> Response:
        """
        Add a bypass/exclude pattern. Matched domains connect directly.

        Parameters
        ----------
        pattern : str
            Bypass pattern: domain (*.example.com, .example.com) or CIDR (10.0.0.0/8)

        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.proxy.add_exclude(
                pattern="*.internal.company.com",
            )


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

    async def remove_exclude(
        self, *, pattern: str, request_options: typing.Optional[RequestOptions] = None
    ) -> Response:
        """
        Remove a bypass/exclude pattern.

        Parameters
        ----------
        pattern : str
            Bypass pattern: domain (*.example.com, .example.com) or CIDR (10.0.0.0/8)

        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.proxy.remove_exclude(
                pattern="*.internal.company.com",
            )


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

    async def diagnose(
        self, *, url: str, request_options: typing.Optional[RequestOptions] = None
    ) -> ResponseProxyDiagnoseResult:
        """
        Diagnose how a URL would be routed through the proxy.

        Parameters
        ----------
        url : str
            URL to diagnose routing for

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

        Returns
        -------
        ResponseProxyDiagnoseResult
            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.proxy.diagnose(
                url="url",
            )


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

    async def get_upstream(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ResponseUnionProxyUpstreamInfoNoneType:
        """
        Get the current upstream proxy configuration.

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

        Returns
        -------
        ResponseUnionProxyUpstreamInfoNoneType
            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.proxy.get_upstream()


        asyncio.run(main())
        """
        _response = await self._raw_client.get_upstream(request_options=request_options)
        return _response.data

    async def set_upstream(
        self,
        *,
        server: str,
        auth_cmd: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ResponseProxyUpstreamInfo:
        """
        Set or update the upstream proxy. Supports user:pass@host:port format.

        Takes effect immediately — no browser restart needed.

        Parameters
        ----------
        server : str
            Upstream proxy server. Supports plain host:port or user:pass@host:port

        auth_cmd : typing.Optional[str]
            Optional shell command to obtain proxy credentials. The command stdout should be "username:password". When set, the result is injected into the server URL, replacing any inline credentials.

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

        Returns
        -------
        ResponseProxyUpstreamInfo
            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.proxy.set_upstream(
                server="proxy.example.com:3128",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.set_upstream(
            server=server, auth_cmd=auth_cmd, request_options=request_options
        )
        return _response.data

    async def remove_upstream(self, *, request_options: typing.Optional[RequestOptions] = None) -> Response:
        """
        Remove upstream proxy (switch to direct mode).

        Parameters
        ----------
        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.proxy.remove_upstream()


        asyncio.run(main())
        """
        _response = await self._raw_client.remove_upstream(request_options=request_options)
        return _response.data
