# 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 UserObject:
    """User Object model."""

    id: str
    """Your application's user identifier, which will be stored as an [`external_id`](https://workos.com/docs/authkit/metadata/external-identifiers). Used for upserting and deduplication."""
    email: str
    """The user's email address."""
    first_name: Optional[str] = None
    """The user's first name."""
    last_name: Optional[str] = None
    """The user's last name."""
    name: Optional[str] = None
    """The user's full name."""
    metadata: Optional[Dict[str, str]] = None
    """A set of key-value pairs to attach to the user."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "UserObject":
        """Deserialize from a dictionary."""
        try:
            return cls(
                id=data["id"],
                email=data["email"],
                first_name=data.get("first_name"),
                last_name=data.get("last_name"),
                name=data.get("name"),
                metadata=data.get("metadata"),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("UserObject", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["id"] = self.id
        result["email"] = self.email
        if self.first_name is not None:
            result["first_name"] = self.first_name
        if self.last_name is not None:
            result["last_name"] = self.last_name
        if self.name is not None:
            result["name"] = self.name
        if self.metadata is not None:
            result["metadata"] = self.metadata
        return result
