# 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 EventContextGoogleAnalyticsSession:
    """Event Context Google Analytics Session model."""

    container_id: str
    """The Google Analytics container ID."""
    session_id: Optional[str] = None
    """The Google Analytics session ID."""
    session_number: Optional[str] = None
    """The Google Analytics session number."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "EventContextGoogleAnalyticsSession":
        """Deserialize from a dictionary."""
        try:
            return cls(
                container_id=data["containerId"],
                session_id=data.get("sessionId"),
                session_number=data.get("sessionNumber"),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("EventContextGoogleAnalyticsSession", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["containerId"] = self.container_id
        if self.session_id is not None:
            result["sessionId"] = self.session_id
        if self.session_number is not None:
            result["sessionNumber"] = self.session_number
        return result
