# 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 .role import Role


@dataclass(slots=True)
class RoleList:
    """Role List model."""

    object: Literal["list"]
    data: List["Role"]
    """The list of records for the current page."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "RoleList":
        """Deserialize from a dictionary."""
        try:
            return cls(
                object=data.get("object", "list"),
                data=[
                    Role.from_dict(cast(Dict[str, Any], item))
                    for item in cast(list[Any], data["data"])
                ],
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("RoleList", e)

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