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

from __future__ import annotations
from .addressupdate import AddressUpdate, AddressUpdateTypedDict
from .createaccountsettings import CreateAccountSettings, CreateAccountSettingsTypedDict
from .patchprofile import PatchProfile, PatchProfileTypedDict
from .phonenumber import PhoneNumber, PhoneNumberTypedDict
from .termsofservicepayloadupdate import (
    TermsOfServicePayloadUpdate,
    TermsOfServicePayloadUpdateTypedDict,
)
from moovio_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
import pydantic
from pydantic import model_serializer
from typing import Dict, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class PatchAccountCustomerSupportTypedDict(TypedDict):
    r"""User-provided information that can be displayed on credit card transactions for customers to use when
    contacting a customer support team. This data is only allowed on a business account.
    """

    phone: NotRequired[PhoneNumberTypedDict]
    email: NotRequired[str]
    address: NotRequired[AddressUpdateTypedDict]
    website: NotRequired[str]


class PatchAccountCustomerSupport(BaseModel):
    r"""User-provided information that can be displayed on credit card transactions for customers to use when
    contacting a customer support team. This data is only allowed on a business account.
    """

    phone: Optional[PhoneNumber] = None

    email: Optional[str] = None

    address: Optional[AddressUpdate] = None

    website: Optional[str] = None

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


class PatchAccountTypedDict(TypedDict):
    r"""Describes the fields available when patching a Moov account."""

    profile: NotRequired[PatchProfileTypedDict]
    r"""Describes the fields available when patching a profile.
    Each object can be patched independent of patching the other fields.
    """
    metadata: NotRequired[Nullable[Dict[str, str]]]
    terms_of_service: NotRequired[TermsOfServicePayloadUpdateTypedDict]
    foreign_id: NotRequired[str]
    customer_support: NotRequired[Nullable[PatchAccountCustomerSupportTypedDict]]
    settings: NotRequired[CreateAccountSettingsTypedDict]


class PatchAccount(BaseModel):
    r"""Describes the fields available when patching a Moov account."""

    profile: Optional[PatchProfile] = None
    r"""Describes the fields available when patching a profile.
    Each object can be patched independent of patching the other fields.
    """

    metadata: OptionalNullable[Dict[str, str]] = UNSET

    terms_of_service: Annotated[
        Optional[TermsOfServicePayloadUpdate], pydantic.Field(alias="termsOfService")
    ] = None

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

    customer_support: Annotated[
        OptionalNullable[PatchAccountCustomerSupport],
        pydantic.Field(alias="customerSupport"),
    ] = UNSET

    settings: Optional[CreateAccountSettings] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "profile",
                "metadata",
                "termsOfService",
                "foreignID",
                "customerSupport",
                "settings",
            ]
        )
        nullable_fields = set(["metadata", "customerSupport"])
        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))
            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


try:
    PatchAccount.model_rebuild()
except NameError:
    pass
