# 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.update_user_password_hash_type import (
    UpdateUserPasswordHashType,
)


@dataclass(slots=True)
class UpdateUser:
    """Update User model."""

    email: str | None = None
    """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."""
    locale: str | None = None
    """The user's preferred locale."""
    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: UpdateUserPasswordHashType | 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]) -> UpdateUser:
        """Deserialize from a dictionary."""
        try:
            return cls(
                email=data.get("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"),
                locale=data.get("locale"),
                password=data.get("password"),
                password_hash=data.get("password_hash"),
                password_hash_type=UpdateUserPasswordHashType(_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("UpdateUser", e)

    def to_dict(self) -> dict[str, Any]:
        """Serialize to a dictionary."""
        result: dict[str, Any] = {}
        if self.email is not None:
            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.email_verified is not None:
            result["email_verified"] = self.email_verified
        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.locale is not None:
            result["locale"] = self.locale
        else:
            result["locale"] = None
        if self.password is not None:
            result["password"] = self.password
        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
