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

from __future__ import annotations

from dataclasses import dataclass
from typing import Any

from workos._types import _raise_deserialize_error


@dataclass(slots=True)
class DeviceAuthorizationResponse:
    """Device Authorization Response model."""

    device_code: str
    """The device verification code."""
    user_code: str
    """The end-user verification code."""
    verification_uri: str
    """The end-user verification URI."""
    expires_in: float
    """Lifetime in seconds of the codes."""
    verification_uri_complete: str | None = None
    """Verification URI that includes the user code."""
    interval: float | None = None
    """Minimum polling interval in seconds."""

    @classmethod
    def from_dict(cls, data: dict[str, Any]) -> DeviceAuthorizationResponse:
        """Deserialize from a dictionary."""
        try:
            return cls(
                device_code=data["device_code"],
                user_code=data["user_code"],
                verification_uri=data["verification_uri"],
                expires_in=data["expires_in"],
                verification_uri_complete=data.get("verification_uri_complete"),
                interval=data.get("interval"),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("DeviceAuthorizationResponse", e)

    def to_dict(self) -> dict[str, Any]:
        """Serialize to a dictionary."""
        result: dict[str, Any] = {}
        result["device_code"] = self.device_code
        result["user_code"] = self.user_code
        result["verification_uri"] = self.verification_uri
        result["expires_in"] = self.expires_in
        if self.verification_uri_complete is not None:
            result["verification_uri_complete"] = self.verification_uri_complete
        if self.interval is not None:
            result["interval"] = self.interval
        return result
