# 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 OrganizationRoleCreatedData:
    """The event payload."""

    object: Literal["organization_role"]
    """Distinguishes the organization role object."""
    organization_id: str
    """The ID of the organization the role belongs to."""
    slug: str
    """The slug identifier of the role."""
    name: str
    """The name of the role."""
    description: Optional[str]
    """A description of the role."""
    resource_type_slug: str
    """The slug of the resource type the role applies to."""
    permissions: List[str]
    """The permissions granted by the role."""
    created_at: datetime
    """An ISO 8601 timestamp."""
    updated_at: datetime
    """An ISO 8601 timestamp."""

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

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