# 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, Literal, Optional
from workos._types import _raise_deserialize_error

from .authentication_oauth_failed_data_error import AuthenticationOAuthFailedDataError


@dataclass(slots=True)
class AuthenticationOAuthFailedData:
    """The event payload."""

    type: Literal["oauth"]
    status: Literal["failed"]
    ip_address: Optional[str]
    """The IP address of the request."""
    user_agent: Optional[str]
    """The user agent of the request."""
    user_id: Optional[str]
    """The ID of the user."""
    email: Optional[str]
    """The email address of the user."""
    error: "AuthenticationOAuthFailedDataError"
    """Details about the authentication error."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "AuthenticationOAuthFailedData":
        """Deserialize from a dictionary."""
        try:
            return cls(
                type=data.get("type", "oauth"),
                status=data.get("status", "failed"),
                ip_address=data["ip_address"],
                user_agent=data["user_agent"],
                user_id=data["user_id"],
                email=data["email"],
                error=AuthenticationOAuthFailedDataError.from_dict(
                    cast(Dict[str, Any], data["error"])
                ),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("AuthenticationOAuthFailedData", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["type"] = self.type
        result["status"] = self.status
        if self.ip_address is not None:
            result["ip_address"] = self.ip_address
        else:
            result["ip_address"] = None
        if self.user_agent is not None:
            result["user_agent"] = self.user_agent
        else:
            result["user_agent"] = None
        if self.user_id is not None:
            result["user_id"] = self.user_id
        else:
            result["user_id"] = None
        if self.email is not None:
            result["email"] = self.email
        else:
            result["email"] = None
        result["error"] = self.error.to_dict()
        return result
