# 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 CreateOrganizationRole:
    """Create Organization Role model."""

    name: str
    """A descriptive name for the role."""
    slug: Optional[str] = None
    """A unique identifier for the role within the organization. When provided, must begin with 'org-' and contain only lowercase letters, numbers, hyphens, and underscores. When omitted, a slug is auto-generated from the role name and a random suffix."""
    description: Optional[str] = None
    """An optional description of the role's purpose."""
    resource_type_slug: Optional[str] = None
    """The slug of the resource type the role is scoped to."""

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

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["name"] = self.name
        if self.slug is not None:
            result["slug"] = self.slug
        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
