# 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, Literal, Optional
from workos._types import _raise_deserialize_error
from workos._types import _format_datetime, _parse_datetime


@dataclass(slots=True)
class AuthorizationPermission:
    """Authorization Permission model."""

    object: Literal["permission"]
    """Distinguishes the Permission object."""
    id: str
    """Unique identifier of the Permission."""
    slug: str
    """A unique key to reference the permission. Must be lowercase and contain only letters, numbers, hyphens, underscores, colons, periods, and asterisks."""
    name: str
    """A descriptive name for the Permission."""
    description: Optional[str]
    """An optional description of the Permission."""
    system: bool
    """Whether the permission is a system permission. System permissions are managed by WorkOS and cannot be deleted."""
    resource_type_slug: str
    """The slug of the resource type associated with the permission."""
    created_at: datetime
    """An ISO 8601 timestamp."""
    updated_at: datetime
    """An ISO 8601 timestamp."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "AuthorizationPermission":
        """Deserialize from a dictionary."""
        try:
            return cls(
                object=data.get("object", "permission"),
                id=data["id"],
                slug=data["slug"],
                name=data["name"],
                description=data["description"],
                system=data["system"],
                resource_type_slug=data["resource_type_slug"],
                created_at=_parse_datetime(data["created_at"]),
                updated_at=_parse_datetime(data["updated_at"]),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("AuthorizationPermission", 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["slug"] = self.slug
        result["name"] = self.name
        if self.description is not None:
            result["description"] = self.description
        else:
            result["description"] = None
        result["system"] = self.system
        result["resource_type_slug"] = self.resource_type_slug
        result["created_at"] = _format_datetime(self.created_at)
        result["updated_at"] = _format_datetime(self.updated_at)
        return result
