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

from __future__ import annotations
from .channelservices import ChannelServices
from .organizationchannelconfig import (
    OrganizationChannelConfig,
    OrganizationChannelConfigTypedDict,
)
from pydantic import model_serializer
from syllable_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from typing import Optional
from typing_extensions import NotRequired, TypedDict


class OrganizationChannelUpdateRequestTypedDict(TypedDict):
    r"""Request model to update a channel through the organizations API"""

    name: str
    r"""The channel name"""
    channel_service: ChannelServices
    r"""The communication service for a channel."""
    config: OrganizationChannelConfigTypedDict
    r"""Channel config information for creates / updates through the organizations API"""
    id: int
    r"""The internal ID of the channel"""
    supported_modes: NotRequired[Nullable[str]]
    r"""The comma-delimited list of supported modes for the channel, which defines the       possible communication methods for channel targets linked to it."""
    is_system_channel: NotRequired[bool]
    r"""Whether the channel is a built-in system channel (i.e., is not customizable)"""


class OrganizationChannelUpdateRequest(BaseModel):
    r"""Request model to update a channel through the organizations API"""

    name: str
    r"""The channel name"""

    channel_service: ChannelServices
    r"""The communication service for a channel."""

    config: OrganizationChannelConfig
    r"""Channel config information for creates / updates through the organizations API"""

    id: int
    r"""The internal ID of the channel"""

    supported_modes: OptionalNullable[str] = UNSET
    r"""The comma-delimited list of supported modes for the channel, which defines the       possible communication methods for channel targets linked to it."""

    is_system_channel: Optional[bool] = True
    r"""Whether the channel is a built-in system channel (i.e., is not customizable)"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["supported_modes", "is_system_channel"])
        nullable_fields = set(["supported_modes"])
        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
