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

from __future__ import annotations

from dataclasses import dataclass
from typing import Any, Dict, Optional
from workos._types import _raise_deserialize_error


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

    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] = None
    """An optional description of the Permission."""
    resource_type_slug: Optional[str] = None
    """The slug of the resource type this permission is scoped to."""

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

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