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

from __future__ import annotations

from dataclasses import dataclass
from typing import cast
from typing import Any, Dict, List, Literal, Optional
from workos._types import _raise_deserialize_error

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


@dataclass(slots=True)
class OrganizationAuthorizedConnectApplicationListData:
    """Organization 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"
    user_id: str
    """The ID of the user who authorized the application."""
    oauth_resource: Optional[str] = None
    """The OAuth resource associated with the authorized connect application, if one was requested."""

    @classmethod
    def from_dict(
        cls, data: Dict[str, Any]
    ) -> "OrganizationAuthorizedConnectApplicationListData":
        """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"])
                ),
                user_id=data["user_id"],
                oauth_resource=data.get("oauth_resource"),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error(
                "OrganizationAuthorizedConnectApplicationListData", 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()
        result["user_id"] = self.user_id
        if self.oauth_resource is not None:
            result["oauth_resource"] = self.oauth_resource
        return result
