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

from __future__ import annotations
from .directoryextension import DirectoryExtension, DirectoryExtensionTypedDict
from datetime import datetime
from pydantic import model_serializer
from syllable_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from typing import Dict, List
from typing_extensions import NotRequired, TypedDict


class DirectoryMemberTypedDict(TypedDict):
    r"""Model for a directory member (i.e. a contact)."""

    name: str
    r"""Name of the directory member"""
    type: str
    r"""Type of the directory member"""
    id: int
    r"""Internal ID of the directory member"""
    updated_at: datetime
    r"""Timestamp of most recent update"""
    extensions: NotRequired[Nullable[List[DirectoryExtensionTypedDict]]]
    r"""List of extensions for the directory member"""
    contact_tags: NotRequired[Nullable[Dict[str, List[str]]]]
    r"""Tags for the directory member"""
    last_updated_by: NotRequired[Nullable[str]]
    r"""Email of the user who last updated the directory member"""


class DirectoryMember(BaseModel):
    r"""Model for a directory member (i.e. a contact)."""

    name: str
    r"""Name of the directory member"""

    type: str
    r"""Type of the directory member"""

    id: int
    r"""Internal ID of the directory member"""

    updated_at: datetime
    r"""Timestamp of most recent update"""

    extensions: OptionalNullable[List[DirectoryExtension]] = UNSET
    r"""List of extensions for the directory member"""

    contact_tags: OptionalNullable[Dict[str, List[str]]] = UNSET
    r"""Tags for the directory member"""

    last_updated_by: OptionalNullable[str] = UNSET
    r"""Email of the user who last updated the directory member"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["extensions", "contact_tags", "last_updated_by"])
        nullable_fields = set(["extensions", "contact_tags", "last_updated_by"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            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
