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

from __future__ import annotations
from .emailconfigurations import EmailConfigurations, EmailConfigurationsTypedDict
from .telephonyconfigurations import (
    TelephonyConfigurations,
    TelephonyConfigurationsTypedDict,
)
from pydantic import model_serializer
from syllable_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from typing import Dict
from typing_extensions import NotRequired, TypedDict


class OrganizationChannelConfigTypedDict(TypedDict):
    r"""Channel config information for creates / updates through the organizations API"""

    account_sid: NotRequired[Nullable[str]]
    r"""SID of the Twilio account"""
    auth_token: NotRequired[Nullable[str]]
    r"""The Twilio auth token"""
    provider_credentials: NotRequired[Nullable[Dict[str, str]]]
    r"""Provider-specific credentials. Initially to be used for AfricasTalking creds.In a future this would be used for Twilio creds too (removing the account_sid and auth_token fields)."""
    telephony: NotRequired[Nullable[TelephonyConfigurationsTypedDict]]
    r"""Telephony configurations to be applied to the targets under the channel"""
    email: NotRequired[Nullable[EmailConfigurationsTypedDict]]
    r"""Email configurations (required for email channels)"""


class OrganizationChannelConfig(BaseModel):
    r"""Channel config information for creates / updates through the organizations API"""

    account_sid: OptionalNullable[str] = UNSET
    r"""SID of the Twilio account"""

    auth_token: OptionalNullable[str] = UNSET
    r"""The Twilio auth token"""

    provider_credentials: OptionalNullable[Dict[str, str]] = UNSET
    r"""Provider-specific credentials. Initially to be used for AfricasTalking creds.In a future this would be used for Twilio creds too (removing the account_sid and auth_token fields)."""

    telephony: OptionalNullable[TelephonyConfigurations] = UNSET
    r"""Telephony configurations to be applied to the targets under the channel"""

    email: OptionalNullable[EmailConfigurations] = UNSET
    r"""Email configurations (required for email channels)"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            ["account_sid", "auth_token", "provider_credentials", "telephony", "email"]
        )
        nullable_fields = set(
            ["account_sid", "auth_token", "provider_credentials", "telephony", "email"]
        )
        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
