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

from __future__ import annotations

from dataclasses import dataclass
from typing import cast
from typing import Any, Dict, List, Literal
from workos._types import _raise_deserialize_error

from .user_consent_option_choice import UserConsentOptionChoice


@dataclass(slots=True)
class UserConsentOption:
    """User Consent Option model."""

    claim: str
    """The claim name for this consent option."""
    type: Literal["enum"]
    """The type of consent option."""
    label: str
    """A human-readable label for this consent option."""
    choices: List["UserConsentOptionChoice"]
    """The available choices for this consent option."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "UserConsentOption":
        """Deserialize from a dictionary."""
        try:
            return cls(
                claim=data["claim"],
                type=data.get("type", "enum"),
                label=data["label"],
                choices=[
                    UserConsentOptionChoice.from_dict(cast(Dict[str, Any], item))
                    for item in cast(list[Any], data["choices"])
                ],
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("UserConsentOption", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["claim"] = self.claim
        result["type"] = self.type
        result["label"] = self.label
        result["choices"] = [item.to_dict() for item in self.choices]
        return result
