# 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 ListMetadata:
    """Cursor-based pagination metadata."""

    after: Optional[str] = None
    """Cursor for the next page of results."""
    before: Optional[str] = None
    """Cursor for the previous page of results."""

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

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