# 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.cli_refresh_response import CliRefreshResponse
from ..types.cli_token_response import CliTokenResponse
from .raw_client import AsyncRawCliAuthenticationClient, RawCliAuthenticationClient

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


class CliAuthenticationClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawCliAuthenticationClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawCliAuthenticationClient
        """
        return self._raw_client

    def refresh_cli_token(
        self, *, refresh_token: str, request_options: typing.Optional[RequestOptions] = None
    ) -> CliRefreshResponse:
        """
        Refresh an expired session JWT using a refresh token.

        Note: Refresh tokens are single-use. The response contains a new refresh_token
        that must replace the old one for future refresh operations.

        Parameters
        ----------
        refresh_token : str
            Refresh token from previous authentication

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

        Returns
        -------
        CliRefreshResponse
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.cli_authentication.refresh_cli_token(
            refresh_token="refresh_token",
        )
        """
        _response = self._raw_client.refresh_cli_token(refresh_token=refresh_token, request_options=request_options)
        return _response.data

    def exchange_cli_token(
        self, *, code: str, code_verifier: str, request_options: typing.Optional[RequestOptions] = None
    ) -> CliTokenResponse:
        """
        Exchange authorization code for session JWT using PKCE.

        Parameters
        ----------
        code : str
            Authorization code from OAuth callback

        code_verifier : str
            PKCE code verifier

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

        Returns
        -------
        CliTokenResponse
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.cli_authentication.exchange_cli_token(
            code="code",
            code_verifier="code_verifier",
        )
        """
        _response = self._raw_client.exchange_cli_token(
            code=code, code_verifier=code_verifier, request_options=request_options
        )
        return _response.data


class AsyncCliAuthenticationClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawCliAuthenticationClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawCliAuthenticationClient
        """
        return self._raw_client

    async def refresh_cli_token(
        self, *, refresh_token: str, request_options: typing.Optional[RequestOptions] = None
    ) -> CliRefreshResponse:
        """
        Refresh an expired session JWT using a refresh token.

        Note: Refresh tokens are single-use. The response contains a new refresh_token
        that must replace the old one for future refresh operations.

        Parameters
        ----------
        refresh_token : str
            Refresh token from previous authentication

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

        Returns
        -------
        CliRefreshResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.cli_authentication.refresh_cli_token(
                refresh_token="refresh_token",
            )


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

    async def exchange_cli_token(
        self, *, code: str, code_verifier: str, request_options: typing.Optional[RequestOptions] = None
    ) -> CliTokenResponse:
        """
        Exchange authorization code for session JWT using PKCE.

        Parameters
        ----------
        code : str
            Authorization code from OAuth callback

        code_verifier : str
            PKCE code verifier

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

        Returns
        -------
        CliTokenResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.cli_authentication.exchange_cli_token(
                code="code",
                code_verifier="code_verifier",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.exchange_cli_token(
            code=code, code_verifier=code_verifier, request_options=request_options
        )
        return _response.data
