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

from __future__ import annotations

from dataclasses import dataclass
from datetime import datetime
from typing import Any, Literal

from workos._types import _format_datetime, _parse_datetime, _raise_deserialize_error


@dataclass(slots=True)
class UserCreateResponse:
    """User Create Response model."""

    object: Literal["user"]
    """Distinguishes the user object."""
    id: str
    """The unique ID of the user."""
    first_name: str | None
    """The first name of the user."""
    last_name: str | None
    """The last name of the user."""
    profile_picture_url: str | None
    """A URL reference to an image representing the user."""
    email: str
    """The email address of the user."""
    email_verified: bool
    """Whether the user's email has been verified."""
    external_id: str | None
    """The external ID of the user."""
    last_sign_in_at: datetime | None
    """The timestamp when the user last signed in."""
    created_at: datetime
    """An ISO 8601 timestamp."""
    updated_at: datetime
    """An ISO 8601 timestamp."""
    name: str | None = None
    """The user's full name."""
    metadata: dict[str, str] | None = None
    """Object containing metadata key/value pairs associated with the user."""
    locale: str | None = None
    """The user's preferred locale."""
    radar_auth_attempt_id: str | None = None
    """The ID of the Radar authentication attempt created for this request when Radar is enabled. Pass this value to the authenticate endpoint to associate the subsequent authentication with this Radar attempt."""

    @classmethod
    def from_dict(cls, data: dict[str, Any]) -> UserCreateResponse:
        """Deserialize from a dictionary."""
        try:
            return cls(
                object=data.get("object", "user"),
                id=data["id"],
                first_name=data["first_name"],
                last_name=data["last_name"],
                profile_picture_url=data["profile_picture_url"],
                email=data["email"],
                email_verified=data["email_verified"],
                external_id=data["external_id"],
                last_sign_in_at=_parse_datetime(_v_last_sign_in_at)
                if (_v_last_sign_in_at := data["last_sign_in_at"]) is not None
                else None,
                created_at=_parse_datetime(data["created_at"]),
                updated_at=_parse_datetime(data["updated_at"]),
                name=data.get("name"),
                metadata=data.get("metadata"),
                locale=data.get("locale"),
                radar_auth_attempt_id=data.get("radar_auth_attempt_id"),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("UserCreateResponse", e)

    def to_dict(self) -> dict[str, Any]:
        """Serialize to a dictionary."""
        result: dict[str, Any] = {}
        result["object"] = self.object
        result["id"] = self.id
        if self.first_name is not None:
            result["first_name"] = self.first_name
        else:
            result["first_name"] = None
        if self.last_name is not None:
            result["last_name"] = self.last_name
        else:
            result["last_name"] = None
        if self.profile_picture_url is not None:
            result["profile_picture_url"] = self.profile_picture_url
        else:
            result["profile_picture_url"] = None
        result["email"] = self.email
        result["email_verified"] = self.email_verified
        if self.external_id is not None:
            result["external_id"] = self.external_id
        else:
            result["external_id"] = None
        if self.last_sign_in_at is not None:
            result["last_sign_in_at"] = _format_datetime(self.last_sign_in_at)
        else:
            result["last_sign_in_at"] = None
        result["created_at"] = _format_datetime(self.created_at)
        result["updated_at"] = _format_datetime(self.updated_at)
        if self.name is not None:
            result["name"] = self.name
        else:
            result["name"] = None
        if self.metadata is not None:
            result["metadata"] = self.metadata
        if self.locale is not None:
            result["locale"] = self.locale
        else:
            result["locale"] = None
        if self.radar_auth_attempt_id is not None:
            result["radar_auth_attempt_id"] = self.radar_auth_attempt_id
        return result
