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

from __future__ import annotations
from .address import Address, AddressTypedDict
from datetime import date, datetime
from paygentic_sdk.types import BaseModel, UNSET_SENTINEL, UnrecognizedStr
import pydantic
from pydantic import model_serializer
from typing import List, Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypedDict


UserObject = Literal["user",]


State = Union[
    Literal[
        "invited",
        "active",
        "suspended",
    ],
    UnrecognizedStr,
]


class UserOrganizationTypedDict(TypedDict):
    id: NotRequired[str]
    r"""Unique identifier for an organization"""
    state: NotRequired[State]


class UserOrganization(BaseModel):
    id: Optional[str] = None
    r"""Unique identifier for an organization"""

    state: Optional[State] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["id", "state"])
        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))

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

        return m


UserType = Union[
    Literal[
        "COMPANY",
        "INDIVIDUAL",
    ],
    UnrecognizedStr,
]


class UserTypedDict(TypedDict):
    id: str
    r"""Unique identifier for a user"""
    created_at: datetime
    email: str
    organizations: List[UserOrganizationTypedDict]
    ory_id: str
    updated_at: datetime
    object: NotRequired[UserObject]
    address: NotRequired[AddressTypedDict]
    date_of_birth: NotRequired[date]
    first_name: NotRequired[str]
    last_name: NotRequired[str]
    phone: NotRequired[str]
    type: NotRequired[UserType]


class User(BaseModel):
    id: str
    r"""Unique identifier for a user"""

    created_at: Annotated[datetime, pydantic.Field(alias="createdAt")]

    email: str

    organizations: List[UserOrganization]

    ory_id: Annotated[str, pydantic.Field(alias="oryId")]

    updated_at: Annotated[datetime, pydantic.Field(alias="updatedAt")]

    object: Optional[UserObject] = "user"

    address: Optional[Address] = None

    date_of_birth: Annotated[Optional[date], pydantic.Field(alias="dateOfBirth")] = None

    first_name: Annotated[Optional[str], pydantic.Field(alias="firstName")] = None

    last_name: Annotated[Optional[str], pydantic.Field(alias="lastName")] = None

    phone: Optional[str] = None

    type: Optional[UserType] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "object",
                "address",
                "dateOfBirth",
                "firstName",
                "lastName",
                "phone",
                "type",
            ]
        )
        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))

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

        return m


try:
    User.model_rebuild()
except NameError:
    pass
