# This file is auto-generated by oagen. Do not edit.

from __future__ import annotations

from dataclasses import dataclass
from datetime import datetime
from typing import Any, Literal

from workos._types import _format_datetime, _parse_datetime, _raise_deserialize_error


@dataclass(slots=True)
class DataIntegrationAccessTokenResponseAccessToken:
    """The [access token](https://workos.com/docs/reference/pipes/access-token) object, present when `active` is `true`."""

    object: Literal["access_token"]
    """Distinguishes the access token object."""
    access_token: str
    """The OAuth access token for the connected integration."""
    expires_at: datetime | None
    """The ISO-8601 formatted timestamp indicating when the access token expires."""
    scopes: list[str]
    """The scopes granted to the access token."""
    missing_scopes: list[str]
    """If the integration has requested scopes that aren't present on the access token, they're listed here."""

    @classmethod
    def from_dict(
        cls, data: dict[str, Any]
    ) -> DataIntegrationAccessTokenResponseAccessToken:
        """Deserialize from a dictionary."""
        try:
            return cls(
                object=data.get("object", "access_token"),
                access_token=data["access_token"],
                expires_at=_parse_datetime(_v_expires_at)
                if (_v_expires_at := data["expires_at"]) is not None
                else None,
                scopes=data["scopes"],
                missing_scopes=data["missing_scopes"],
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("DataIntegrationAccessTokenResponseAccessToken", e)

    def to_dict(self) -> dict[str, Any]:
        """Serialize to a dictionary."""
        result: dict[str, Any] = {}
        result["object"] = self.object
        result["access_token"] = self.access_token
        if self.expires_at is not None:
            result["expires_at"] = _format_datetime(self.expires_at)
        else:
            result["expires_at"] = None
        result["scopes"] = self.scopes
        result["missing_scopes"] = self.missing_scopes
        return result
