"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from factify.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
from pydantic import model_serializer
from typing_extensions import NotRequired, TypedDict


class UserTypedDict(TypedDict):
    r"""User represents a human user account.
    Returned by GetUser (endpoint deferred).
    """

    email: str
    id: str
    name: str
    r"""Display name of the user."""
    family_name: NotRequired[Nullable[str]]
    r"""Family name (last name) of the user."""
    given_name: NotRequired[Nullable[str]]
    r"""Given name (first name) of the user."""
    profile_image_url: NotRequired[Nullable[str]]
    r"""URL of the user's profile image."""


class User(BaseModel):
    r"""User represents a human user account.
    Returned by GetUser (endpoint deferred).
    """

    email: str

    id: str

    name: str
    r"""Display name of the user."""

    family_name: OptionalNullable[str] = UNSET
    r"""Family name (last name) of the user."""

    given_name: OptionalNullable[str] = UNSET
    r"""Given name (first name) of the user."""

    profile_image_url: OptionalNullable[str] = UNSET
    r"""URL of the user's profile image."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["family_name", "given_name", "profile_image_url"])
        nullable_fields = set(["family_name", "given_name", "profile_image_url"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

            if val != UNSET_SENTINEL:
                if (
                    val is not None
                    or k not in optional_fields
                    or is_nullable_and_explicitly_set
                ):
                    m[k] = val

        return m
