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

from __future__ import annotations

from dataclasses import dataclass
from typing import Any, Literal

from workos._types import _raise_deserialize_error


@dataclass(slots=True)
class DataIntegrationCredentialsResponseCredential:
    """The credential object containing the vended secret."""

    object: Literal["credential"]
    """Distinguishes the credential object."""
    auth_method: Literal["oauth"]
    """The authentication method for this credential. Additional values may be added in the future; handle unknown values gracefully."""
    value: str
    """The OAuth access token."""
    expires_at: str | None
    """The ISO-8601 formatted timestamp indicating when the credential 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]
    ) -> DataIntegrationCredentialsResponseCredential:
        """Deserialize from a dictionary."""
        try:
            return cls(
                object=data.get("object", "credential"),
                auth_method=data.get("auth_method", "oauth"),
                value=data["value"],
                expires_at=data["expires_at"],
                scopes=data["scopes"],
                missing_scopes=data["missing_scopes"],
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("DataIntegrationCredentialsResponseCredential", e)

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