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

from ..core.unchecked_base_model import UncheckedBaseModel
import typing
import pydantic
from .error import Error
from ..core.pydantic_utilities import IS_PYDANTIC_V2


class ObtainTokenResponse(UncheckedBaseModel):
    """
    Represents an [ObtainToken](api-endpoint:OAuth-ObtainToken) response.
    """

    access_token: typing.Optional[str] = pydantic.Field(default=None)
    """
    An OAuth access token used to authorize Square API requests on behalf of the seller.
    Include this token as a bearer token in the `Authorization` header of your API requests.
    
    OAuth access tokens expire in 30 days (except `short_lived` access tokens). You should call
    `ObtainToken` and provide the returned `refresh_token` to get a new access token well before
    the current one expires. For more information, see [OAuth API: Walkthrough](https://developer.squareup.com/docs/oauth-api/walkthrough).
    """

    token_type: typing.Optional[str] = pydantic.Field(default=None)
    """
    The type of access token. This value is always `bearer`.
    """

    expires_at: typing.Optional[str] = pydantic.Field(default=None)
    """
    The timestamp of when the `access_token` expires, in [ISO 8601](http://www.iso.org/iso/home/standards/iso8601.htm) format.
    """

    merchant_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    The ID of the authorizing [merchant](entity:Merchant) (seller), which represents a business.
    """

    subscription_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    __LEGACY__ The ID of merchant's subscription.
    The ID is only present if the merchant signed up for a subscription plan during authorization.
    """

    plan_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    __LEGACY__ The ID of the subscription plan the merchant signed
    up for. The ID is only present if the merchant signed up for a subscription plan during
    authorization.
    """

    id_token: typing.Optional[str] = pydantic.Field(default=None)
    """
    The OpenID token that belongs to this person. This token is only present if the
    `OPENID` scope is included in the authorization request.
    
    Deprecated at version 2021-09-15. Square doesn't support OpenID or other single sign-on (SSO)
    protocols on top of OAuth.
    """

    refresh_token: typing.Optional[str] = pydantic.Field(default=None)
    """
    A refresh token that can be used in an `ObtainToken` request to generate a new access token.
    
    With the code flow:
    - For the `authorization_code` grant type, the refresh token is multi-use and never expires.
    - For the `refresh_token` grant type, the response returns the same refresh token.
    
    With the PKCE flow:
    - For the `authorization_code` grant type, the refresh token is single-use and expires in 90 days.
    - For the `refresh_token` grant type, the refresh token is a new single-use refresh token that expires in 90 days.
    
    For more information, see [Refresh, Revoke, and Limit the Scope of OAuth Tokens](https://developer.squareup.com/docs/oauth-api/refresh-revoke-limit-scope).
    """

    short_lived: typing.Optional[bool] = pydantic.Field(default=None)
    """
    Indicates whether the access_token is short lived. If `true`, the access token expires
    in 24 hours. If `false`, the access token expires in 30 days.
    """

    errors: typing.Optional[typing.List[Error]] = pydantic.Field(default=None)
    """
    Any errors that occurred during the request.
    """

    refresh_token_expires_at: typing.Optional[str] = pydantic.Field(default=None)
    """
    The timestamp of when the `refresh_token` expires, in [ISO 8601](http://www.iso.org/iso/home/standards/iso8601.htm)
    format.
    
    This field is only returned for the PKCE flow.
    """

    if IS_PYDANTIC_V2:
        model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True)  # type: ignore # Pydantic v2
    else:

        class Config:
            frozen = True
            smart_union = True
            extra = pydantic.Extra.allow
