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

from __future__ import annotations

from dataclasses import dataclass
from datetime import datetime
from enum import Enum
from typing import Any, Dict, Literal, Optional
from workos._types import _raise_deserialize_error
from workos._types import _format_datetime, _parse_datetime
from .dsync_deleted_data_state import DsyncDeletedDataState
from .dsync_deleted_data_type import DsyncDeletedDataType


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

    object: Literal["directory"]
    """Distinguishes the directory object."""
    id: str
    """Unique identifier of the directory."""
    type: "DsyncDeletedDataType"
    """The type of the directory."""
    state: "DsyncDeletedDataState"
    """The current state of the directory."""
    name: str
    """The name of the directory."""
    created_at: datetime
    """An ISO 8601 timestamp."""
    updated_at: datetime
    """An ISO 8601 timestamp."""
    organization_id: Optional[str] = None
    """The ID of the organization the directory belongs to."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "DsyncDeletedData":
        """Deserialize from a dictionary."""
        try:
            return cls(
                object=data.get("object", "directory"),
                id=data["id"],
                type=DsyncDeletedDataType(data["type"]),
                state=DsyncDeletedDataState(data["state"]),
                name=data["name"],
                created_at=_parse_datetime(data["created_at"]),
                updated_at=_parse_datetime(data["updated_at"]),
                organization_id=data.get("organization_id"),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("DsyncDeletedData", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["object"] = self.object
        result["id"] = self.id
        result["type"] = self.type.value if isinstance(self.type, Enum) else self.type
        result["state"] = (
            self.state.value if isinstance(self.state, Enum) else self.state
        )
        result["name"] = self.name
        result["created_at"] = _format_datetime(self.created_at)
        result["updated_at"] = _format_datetime(self.updated_at)
        if self.organization_id is not None:
            result["organization_id"] = self.organization_id
        return result
