# 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 CheckAuthorization:
    """Check Authorization model."""

    permission_slug: str
    """The slug of the permission to check."""
    resource_id: Optional[str] = None
    """The ID of the resource. Mutually exclusive with `resource_external_id` and `resource_type_slug`."""
    resource_external_id: Optional[str] = None
    """The external ID of the resource. Required with `resource_type_slug`. Mutually exclusive with `resource_id`."""
    resource_type_slug: Optional[str] = None
    """The slug of the resource type. Required with `resource_external_id`. Mutually exclusive with `resource_id`."""

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

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