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

    object: Literal["authorization_resource"]
    """Distinguishes the Resource object."""
    name: str
    """A human-readable name for the Resource."""
    description: Optional[str]
    """An optional description of the Resource."""
    organization_id: str
    """The ID of the organization that owns the resource."""
    parent_resource_id: Optional[str]
    """The ID of the parent resource, if this resource is nested."""
    id: str
    """The unique ID of the Resource."""
    external_id: str
    """An identifier you provide to reference the resource in your system."""
    resource_type_slug: str
    """The slug of the resource type this resource belongs to."""
    created_at: datetime
    """An ISO 8601 timestamp."""
    updated_at: datetime
    """An ISO 8601 timestamp."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "AuthorizationResource":
        """Deserialize from a dictionary."""
        try:
            return cls(
                object=data.get("object", "authorization_resource"),
                name=data["name"],
                description=data["description"],
                organization_id=data["organization_id"],
                parent_resource_id=data["parent_resource_id"],
                id=data["id"],
                external_id=data["external_id"],
                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("AuthorizationResource", e)

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