"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from attio.types import BaseModel, Nullable, UNSET_SENTINEL
from attio.utils import validate_const
import pydantic
from pydantic import model_serializer
from pydantic.functional_validators import AfterValidator
from typing import Literal, Union
from typing_extensions import Annotated, TypeAliasType, TypedDict


TokenType = Literal["Bearer",]
r"""The type of token, always Bearer for tokens acquired via the OAuth 2.0 flow."""


Iss = Literal["attio.com",]
r"""The issuer of the token. Always attio.com"""


class AttioComTypedDict(TypedDict):
    active: bool
    r"""Whether the token is currently active and usable."""
    scope: str
    r"""A space-separated list of scopes associated with this token"""
    client_id: str
    r"""The app ID of the OAuth application that requested this token"""
    token_type: TokenType
    r"""The type of token, always Bearer for tokens acquired via the OAuth 2.0 flow."""
    exp: Nullable[float]
    r"""The time at which this token will expire, if set, as a number of seconds since January 1 1970 UTC."""
    iat: float
    r"""The time at which this token was issued, as a number of seconds since January 1 1970 UTC."""
    sub: str
    r"""Since Bearer tokens grant Workspace-level permissions, this property contains the workspace_id."""
    aud: str
    r"""The intended audience for this token, for Bearer tokens this is the same as the client_id."""
    iss: Iss
    r"""The issuer of the token. Always attio.com"""
    authorized_by_workspace_member_id: str
    r"""The ID of the workspace member who authorised this token initially."""
    workspace_id: str
    r"""The ID of the workspace the token is scoped to."""
    workspace_name: str
    r"""The name of the workspace the token is scoped to."""
    workspace_slug: str
    r"""The slug of the workspace the token is scoped to."""
    workspace_logo_url: Nullable[str]
    r"""The logo URL of the workspace the token is scoped to."""


class AttioCom(BaseModel):
    active: bool
    r"""Whether the token is currently active and usable."""

    scope: str
    r"""A space-separated list of scopes associated with this token"""

    client_id: str
    r"""The app ID of the OAuth application that requested this token"""

    token_type: TokenType
    r"""The type of token, always Bearer for tokens acquired via the OAuth 2.0 flow."""

    exp: Nullable[float]
    r"""The time at which this token will expire, if set, as a number of seconds since January 1 1970 UTC."""

    iat: float
    r"""The time at which this token was issued, as a number of seconds since January 1 1970 UTC."""

    sub: str
    r"""Since Bearer tokens grant Workspace-level permissions, this property contains the workspace_id."""

    aud: str
    r"""The intended audience for this token, for Bearer tokens this is the same as the client_id."""

    iss: Iss
    r"""The issuer of the token. Always attio.com"""

    authorized_by_workspace_member_id: str
    r"""The ID of the workspace member who authorised this token initially."""

    workspace_id: str
    r"""The ID of the workspace the token is scoped to."""

    workspace_name: str
    r"""The name of the workspace the token is scoped to."""

    workspace_slug: str
    r"""The slug of the workspace the token is scoped to."""

    workspace_logo_url: Nullable[str]
    r"""The logo URL of the workspace the token is scoped to."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))

            if val != UNSET_SENTINEL:
                m[k] = val

        return m


class ResponseBodyTypedDict(TypedDict):
    active: Literal[False]


class ResponseBody(BaseModel):
    ACTIVE: Annotated[
        Annotated[Literal[False], AfterValidator(validate_const(False))],
        pydantic.Field(alias="active"),
    ] = False


GetV2SelfResponseTypedDict = TypeAliasType(
    "GetV2SelfResponseTypedDict", Union[ResponseBodyTypedDict, AttioComTypedDict]
)
r"""Success"""


GetV2SelfResponse = TypeAliasType("GetV2SelfResponse", Union[ResponseBody, AttioCom])
r"""Success"""


try:
    ResponseBody.model_rebuild()
except NameError:
    pass
