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

from .directory_group import DirectoryGroup
from .directory_user import DirectoryUser


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

    directory_id: str
    """The ID of the directory."""
    user: "DirectoryUser"
    """The directory user added to the group."""
    group: "DirectoryGroup"
    """The directory group the user was added to."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "DsyncGroupUserAddedData":
        """Deserialize from a dictionary."""
        try:
            return cls(
                directory_id=data["directory_id"],
                user=DirectoryUser.from_dict(cast(Dict[str, Any], data["user"])),
                group=DirectoryGroup.from_dict(cast(Dict[str, Any], data["group"])),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("DsyncGroupUserAddedData", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["directory_id"] = self.directory_id
        result["user"] = self.user.to_dict()
        result["group"] = self.group.to_dict()
        return result
