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

from __future__ import annotations
from datetime import datetime
from flowai_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing import Optional
from typing_extensions import NotRequired, TypedDict


class UserReadTypedDict(TypedDict):
    r"""Schema for reading/returning user data, aligned with DB model."""

    id: str
    created_at: datetime
    updated_at: datetime
    email: NotRequired[Nullable[str]]
    first_name: NotRequired[Nullable[str]]
    last_name: NotRequired[Nullable[str]]
    username: NotRequired[Nullable[str]]
    image_url: NotRequired[Nullable[str]]
    org_id: NotRequired[Nullable[str]]
    is_active: NotRequired[bool]
    clerk_id: NotRequired[Nullable[str]]


class UserRead(BaseModel):
    r"""Schema for reading/returning user data, aligned with DB model."""

    id: str

    created_at: datetime

    updated_at: datetime

    email: OptionalNullable[str] = UNSET

    first_name: OptionalNullable[str] = UNSET

    last_name: OptionalNullable[str] = UNSET

    username: OptionalNullable[str] = UNSET

    image_url: OptionalNullable[str] = UNSET

    org_id: OptionalNullable[str] = UNSET

    is_active: Optional[bool] = True

    clerk_id: OptionalNullable[str] = UNSET

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "email",
            "first_name",
            "last_name",
            "username",
            "image_url",
            "org_id",
            "is_active",
            "clerk_id",
        ]
        nullable_fields = [
            "email",
            "first_name",
            "last_name",
            "username",
            "image_url",
            "org_id",
            "clerk_id",
        ]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            serialized.pop(k, None)

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m
