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

from __future__ import annotations

from dataclasses import dataclass
from datetime import datetime
from typing import Any, Dict, List, Literal, Optional
from workos._types import _raise_deserialize_error
from workos._types import _format_datetime, _parse_datetime


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

    object: Literal["role"]
    """Distinguishes the role object."""
    slug: str
    """The slug identifier of the role."""
    resource_type_slug: str
    """The slug of the resource type the role applies to."""
    created_at: datetime
    """An ISO 8601 timestamp."""
    updated_at: datetime
    """An ISO 8601 timestamp."""
    permissions: Optional[List[str]] = None
    """The permissions granted by the role."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "RoleCreatedData":
        """Deserialize from a dictionary."""
        try:
            return cls(
                object=data.get("object", "role"),
                slug=data["slug"],
                resource_type_slug=data["resource_type_slug"],
                created_at=_parse_datetime(data["created_at"]),
                updated_at=_parse_datetime(data["updated_at"]),
                permissions=data.get("permissions"),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("RoleCreatedData", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["object"] = self.object
        result["slug"] = self.slug
        result["resource_type_slug"] = self.resource_type_slug
        result["created_at"] = _format_datetime(self.created_at)
        result["updated_at"] = _format_datetime(self.updated_at)
        if self.permissions is not None:
            result["permissions"] = self.permissions
        return result
