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

from __future__ import annotations

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


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

    action_endpoint_id: str
    """The ID of the action endpoint."""
    action_execution_id: str
    """The ID of the action execution."""
    type: Literal["authentication"]
    """The type of action that was denied."""
    verdict: Literal["Deny"]
    """The verdict of the action."""
    user_id: str
    """The ID of the user."""
    organization_id: Optional[str]
    """The ID of the organization."""
    email: str
    """The email address of the user."""
    ip_address: Optional[str]
    """The IP address of the request."""
    user_agent: Optional[str]
    """The user agent of the request."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "ActionAuthenticationDeniedData":
        """Deserialize from a dictionary."""
        try:
            return cls(
                action_endpoint_id=data["action_endpoint_id"],
                action_execution_id=data["action_execution_id"],
                type=data.get("type", "authentication"),
                verdict=data.get("verdict", "Deny"),
                user_id=data["user_id"],
                organization_id=data["organization_id"],
                email=data["email"],
                ip_address=data["ip_address"],
                user_agent=data["user_agent"],
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("ActionAuthenticationDeniedData", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["action_endpoint_id"] = self.action_endpoint_id
        result["action_execution_id"] = self.action_execution_id
        result["type"] = self.type
        result["verdict"] = self.verdict
        result["user_id"] = self.user_id
        if self.organization_id is not None:
            result["organization_id"] = self.organization_id
        else:
            result["organization_id"] = None
        result["email"] = self.email
        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
        return result
