# 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.auth_token_auth_token_response_body import AuthTokenAuthTokenResponseBody
from .raw_client import AsyncRawAuthTokenForDriverClient, RawAuthTokenForDriverClient

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


class AuthTokenForDriverClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawAuthTokenForDriverClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawAuthTokenForDriverClient
        """
        return self._raw_client

    def auth_token(
        self,
        *,
        code: str,
        driver_id: typing.Optional[int] = OMIT,
        external_id: typing.Optional[str] = OMIT,
        username: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AuthTokenAuthTokenResponseBody:
        """
        Creates a short-lived auth token a driver can use to login.

         <b>Rate limit:</b> 100 requests/min (learn more about rate limits <a href="https://developers.samsara.com/docs/rate-limits" target="_blank">here</a>).

        To use this endpoint, select **Write Driver Auth Token** under the Drivers category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>


         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        Parameters
        ----------
        code : str
            Required. Random 12+ character string, used with the auth token to help secure the client from intercepted tokens.

        driver_id : typing.Optional[int]
            Optional. Samsara ID of the driver. One of `id`, `externalId`, or `username` is required.

        external_id : typing.Optional[str]
            Optional. External ID of the driver, in the format `key:value` (e.g., `payrollId:ABFS18600`). One of `id`, `externalId`, or `username` is required.

        username : typing.Optional[str]
            Optional. Username of the driver. This is the login identifier configured when the driver is created. One of `id`, `externalId`, or `username` is required.

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

        Returns
        -------
        AuthTokenAuthTokenResponseBody
            OK response.

        Examples
        --------
        from samsara import Samsara

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.auth_token_for_driver.auth_token(
            code="dp[gZc1wAigz4uGa0Hh",
        )
        """
        _response = self._raw_client.auth_token(
            code=code, driver_id=driver_id, external_id=external_id, username=username, request_options=request_options
        )
        return _response.data


class AsyncAuthTokenForDriverClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawAuthTokenForDriverClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawAuthTokenForDriverClient
        """
        return self._raw_client

    async def auth_token(
        self,
        *,
        code: str,
        driver_id: typing.Optional[int] = OMIT,
        external_id: typing.Optional[str] = OMIT,
        username: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AuthTokenAuthTokenResponseBody:
        """
        Creates a short-lived auth token a driver can use to login.

         <b>Rate limit:</b> 100 requests/min (learn more about rate limits <a href="https://developers.samsara.com/docs/rate-limits" target="_blank">here</a>).

        To use this endpoint, select **Write Driver Auth Token** under the Drivers category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>


         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        Parameters
        ----------
        code : str
            Required. Random 12+ character string, used with the auth token to help secure the client from intercepted tokens.

        driver_id : typing.Optional[int]
            Optional. Samsara ID of the driver. One of `id`, `externalId`, or `username` is required.

        external_id : typing.Optional[str]
            Optional. External ID of the driver, in the format `key:value` (e.g., `payrollId:ABFS18600`). One of `id`, `externalId`, or `username` is required.

        username : typing.Optional[str]
            Optional. Username of the driver. This is the login identifier configured when the driver is created. One of `id`, `externalId`, or `username` is required.

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

        Returns
        -------
        AuthTokenAuthTokenResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.auth_token_for_driver.auth_token(
                code="dp[gZc1wAigz4uGa0Hh",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.auth_token(
            code=code, driver_id=driver_id, external_id=external_id, username=username, request_options=request_options
        )
        return _response.data
