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

from __future__ import annotations

from dataclasses import dataclass
from datetime import datetime
from enum import Enum
from typing import Any, Dict, Literal, Optional
from workos._types import _raise_deserialize_error
from workos._types import _format_datetime, _parse_datetime
from .waitlist_user_state import WaitlistUserState


@dataclass(slots=True)
class WaitlistUser:
    """Waitlist User model."""

    object: Literal["waitlist_user"]
    """Distinguishes the Waitlist User object."""
    id: str
    """The unique ID of the Waitlist User."""
    email: str
    """The email address of the Waitlist User."""
    state: "WaitlistUserState"
    """The state of the Waitlist User."""
    approved_at: Optional[datetime]
    """The timestamp when the Waitlist User was approved, or null if not yet approved."""
    created_at: datetime
    """An ISO 8601 timestamp."""
    updated_at: datetime
    """An ISO 8601 timestamp."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "WaitlistUser":
        """Deserialize from a dictionary."""
        try:
            return cls(
                object=data.get("object", "waitlist_user"),
                id=data["id"],
                email=data["email"],
                state=WaitlistUserState(data["state"]),
                approved_at=_parse_datetime(_v_approved_at)
                if (_v_approved_at := data["approved_at"]) is not None
                else None,
                created_at=_parse_datetime(data["created_at"]),
                updated_at=_parse_datetime(data["updated_at"]),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("WaitlistUser", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["object"] = self.object
        result["id"] = self.id
        result["email"] = self.email
        result["state"] = (
            self.state.value if isinstance(self.state, Enum) else self.state
        )
        if self.approved_at is not None:
            result["approved_at"] = _format_datetime(self.approved_at)
        else:
            result["approved_at"] = None
        result["created_at"] = _format_datetime(self.created_at)
        result["updated_at"] = _format_datetime(self.updated_at)
        return result
