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

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


class PhoneTypedDict(TypedDict):
    phone_number: Nullable[str]
    r"""The phone number starting with a plus (+) followed by the country code (e.g +336676778890 for France)"""
    phone_type: Nullable[str]
    r"""The phone type. Authorized values are either MOBILE or WORK"""
    owner_type: NotRequired[Nullable[str]]
    r"""The owner type of a phone number"""
    

class Phone(BaseModel):
    phone_number: Nullable[str]
    r"""The phone number starting with a plus (+) followed by the country code (e.g +336676778890 for France)"""
    phone_type: Nullable[str]
    r"""The phone type. Authorized values are either MOBILE or WORK"""
    owner_type: OptionalNullable[str] = UNSET
    r"""The owner type of a phone number"""
    
    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["owner_type"]
        nullable_fields = ["phone_number", "phone_type", "owner_type"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

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

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields
                or (
                    k in optional_fields
                    and k in nullable_fields
                    and (
                        self.__pydantic_fields_set__.intersection({n})
                        or k in null_default_fields
                    )  # pylint: disable=no-member
                )
            ):
                m[k] = val

        return m
        
