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

from __future__ import annotations

from dataclasses import dataclass
from enum import Enum
from typing import Any

from workos._types import _raise_deserialize_error
from workos.common.models.create_user_password_hash_type import (
    CreateUserPasswordHashType,
)


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

    email: str
    """The email address of the user."""
    first_name: str | None = None
    """The first name of the user."""
    last_name: str | None = None
    """The last name of the user."""
    name: str | None = None
    """The user's full name."""
    email_verified: bool | None = None
    """Whether the user's email has been verified."""
    metadata: dict[str, str] | None = None
    """Object containing metadata key/value pairs associated with the user."""
    external_id: str | None = None
    """The external ID of the user."""
    ip_address: str | None = None
    """The IP address of the user's request."""
    user_agent: str | None = None
    """The user agent string from the user's request."""
    signals_id: str | None = None
    """An optional Radar signals ID to correlate client-side signals with this request."""
    password: str | None = None
    """The password to set for the user. Mutually exclusive with `password_hash` and `password_hash_type`."""
    password_hash: str | None = None
    """The hashed password to set for the user. Required with `password_hash_type`. Mutually exclusive with `password`."""
    password_hash_type: CreateUserPasswordHashType | None = None
    """The algorithm originally used to hash the password, used when providing a `password_hash`. Required with `password_hash`. Mutually exclusive with `password`."""

    @classmethod
    def from_dict(cls, data: dict[str, Any]) -> CreateUser:
        """Deserialize from a dictionary."""
        try:
            return cls(
                email=data["email"],
                first_name=data.get("first_name"),
                last_name=data.get("last_name"),
                name=data.get("name"),
                email_verified=data.get("email_verified"),
                metadata=data.get("metadata"),
                external_id=data.get("external_id"),
                ip_address=data.get("ip_address"),
                user_agent=data.get("user_agent"),
                signals_id=data.get("signals_id"),
                password=data.get("password"),
                password_hash=data.get("password_hash"),
                password_hash_type=CreateUserPasswordHashType(_v_password_hash_type)
                if (_v_password_hash_type := data.get("password_hash_type")) is not None
                else None,
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("CreateUser", e)

    def to_dict(self) -> dict[str, Any]:
        """Serialize to a dictionary."""
        result: dict[str, Any] = {}
        result["email"] = self.email
        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.name is not None:
            result["name"] = self.name
        else:
            result["name"] = None
        if self.email_verified is not None:
            result["email_verified"] = self.email_verified
        else:
            result["email_verified"] = None
        if self.metadata is not None:
            result["metadata"] = self.metadata
        else:
            result["metadata"] = None
        if self.external_id is not None:
            result["external_id"] = self.external_id
        else:
            result["external_id"] = None
        if self.ip_address is not None:
            result["ip_address"] = self.ip_address
        else:
            result["ip_address"] = None
        if self.user_agent is not None:
            result["user_agent"] = self.user_agent
        else:
            result["user_agent"] = None
        if self.signals_id is not None:
            result["signals_id"] = self.signals_id
        if self.password is not None:
            result["password"] = self.password
        else:
            result["password"] = None
        if self.password_hash is not None:
            result["password_hash"] = self.password_hash
        if self.password_hash_type is not None:
            result["password_hash_type"] = (
                self.password_hash_type.value
                if isinstance(self.password_hash_type, Enum)
                else self.password_hash_type
            )
        return result
