# 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 CreateAuthorizationResource:
    """Create Authorization Resource model."""

    external_id: str
    """An external identifier for the resource."""
    name: str
    """A display name for the resource."""
    resource_type_slug: str
    """The slug of the resource type."""
    organization_id: str
    """The ID of the organization this resource belongs to."""
    description: Optional[str] = None
    """An optional description of the resource."""
    parent_resource_id: Optional[str] = None
    """The ID of the parent resource. Mutually exclusive with `parent_resource_external_id` and `parent_resource_type_slug`."""
    parent_resource_external_id: Optional[str] = None
    """The external ID of the parent resource. Required with `parent_resource_type_slug`. Mutually exclusive with `parent_resource_id`."""
    parent_resource_type_slug: Optional[str] = None
    """The resource type slug of the parent resource. Required with `parent_resource_external_id`. Mutually exclusive with `parent_resource_id`."""

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

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