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

from __future__ import annotations

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


@dataclass(slots=True)
class AuditLogEventContext:
    """Audit Log Event Context model."""

    location: str
    """IP Address or some other geolocation identifier."""
    user_agent: Optional[str] = None
    """User agent string."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "AuditLogEventContext":
        """Deserialize from a dictionary."""
        try:
            return cls(
                location=data["location"],
                user_agent=data.get("user_agent"),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("AuditLogEventContext", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["location"] = self.location
        if self.user_agent is not None:
            result["user_agent"] = self.user_agent
        return result
