# This file was auto-generated by Fern from our API Definition.

import typing
from ..core.client_wrapper import SyncClientWrapper
from .raw_client import RawMobileClient
from ..core.request_options import RequestOptions
from ..types.create_mobile_authorization_code_response import CreateMobileAuthorizationCodeResponse
from ..core.client_wrapper import AsyncClientWrapper
from .raw_client import AsyncRawMobileClient

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


class MobileClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawMobileClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawMobileClient
        """
        return self._raw_client

    def authorization_code(
        self, *, location_id: typing.Optional[str] = OMIT, request_options: typing.Optional[RequestOptions] = None
    ) -> CreateMobileAuthorizationCodeResponse:
        """
        __Note:__ This endpoint is used by the deprecated Reader SDK.
        Developers should update their integration to use the [Mobile Payments SDK](https://developer.squareup.com/docs/mobile-payments-sdk), which includes its own authorization methods.

        Generates code to authorize a mobile application to connect to a Square card reader.

        Authorization codes are one-time-use codes and expire 60 minutes after being issued.

        The `Authorization` header you provide to this endpoint must have the following format:

        ```
        Authorization: Bearer ACCESS_TOKEN
        ```

        Replace `ACCESS_TOKEN` with a
        [valid production authorization credential](https://developer.squareup.com/docs/build-basics/access-tokens).

        Parameters
        ----------
        location_id : typing.Optional[str]
            The Square location ID that the authorization code should be tied to.

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

        Returns
        -------
        CreateMobileAuthorizationCodeResponse
            Success

        Examples
        --------
        from square import Square

        client = Square(
            token="YOUR_TOKEN",
        )
        client.mobile.authorization_code(
            location_id="YOUR_LOCATION_ID",
        )
        """
        response = self._raw_client.authorization_code(location_id=location_id, request_options=request_options)
        return response.data


class AsyncMobileClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawMobileClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawMobileClient
        """
        return self._raw_client

    async def authorization_code(
        self, *, location_id: typing.Optional[str] = OMIT, request_options: typing.Optional[RequestOptions] = None
    ) -> CreateMobileAuthorizationCodeResponse:
        """
        __Note:__ This endpoint is used by the deprecated Reader SDK.
        Developers should update their integration to use the [Mobile Payments SDK](https://developer.squareup.com/docs/mobile-payments-sdk), which includes its own authorization methods.

        Generates code to authorize a mobile application to connect to a Square card reader.

        Authorization codes are one-time-use codes and expire 60 minutes after being issued.

        The `Authorization` header you provide to this endpoint must have the following format:

        ```
        Authorization: Bearer ACCESS_TOKEN
        ```

        Replace `ACCESS_TOKEN` with a
        [valid production authorization credential](https://developer.squareup.com/docs/build-basics/access-tokens).

        Parameters
        ----------
        location_id : typing.Optional[str]
            The Square location ID that the authorization code should be tied to.

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

        Returns
        -------
        CreateMobileAuthorizationCodeResponse
            Success

        Examples
        --------
        import asyncio

        from square import AsyncSquare

        client = AsyncSquare(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.mobile.authorization_code(
                location_id="YOUR_LOCATION_ID",
            )


        asyncio.run(main())
        """
        response = await self._raw_client.authorization_code(location_id=location_id, request_options=request_options)
        return response.data
