"""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 = ["extensions", "contact_tags", "last_updated_by"]
        nullable_fields = ["extensions", "contact_tags", "last_updated_by"]
        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
