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

from __future__ import annotations

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

from workos._types import _raise_deserialize_error
from workos.common.models.connect_application import (
    ConnectApplication,
    ConnectApplicationVariant,
)


@dataclass(slots=True)
class AuthorizedConnectApplicationListData:
    """Authorized Connect Application List Data model."""

    object: Literal["authorized_connect_application"]
    """Distinguishes the authorized connect application object."""
    id: str
    """The unique ID of the authorized connect application."""
    granted_scopes: list[str]
    """The scopes granted by the user to the application."""
    application: ConnectApplicationVariant
    oauth_resource: str | None = None
    """The OAuth resource associated with the authorized connect application, if one was requested."""

    @classmethod
    def from_dict(cls, data: dict[str, Any]) -> AuthorizedConnectApplicationListData:
        """Deserialize from a dictionary."""
        try:
            return cls(
                object=data.get("object", "authorized_connect_application"),
                id=data["id"],
                granted_scopes=data["granted_scopes"],
                application=ConnectApplication.from_dict(
                    cast(dict[str, Any], data["application"])
                ),
                oauth_resource=data.get("oauth_resource"),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("AuthorizedConnectApplicationListData", e)

    def to_dict(self) -> dict[str, Any]:
        """Serialize to a dictionary."""
        result: dict[str, Any] = {}
        result["object"] = self.object
        result["id"] = self.id
        result["granted_scopes"] = self.granted_scopes
        result["application"] = self.application.to_dict()
        if self.oauth_resource is not None:
            result["oauth_resource"] = self.oauth_resource
        return result
