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

from __future__ import annotations
from .slackchannelendpointdto import (
    SlackChannelEndpointDto,
    SlackChannelEndpointDtoTypedDict,
)
from enum import Enum
from novu_py.types import BaseModel, UNSET_SENTINEL
import pydantic
from pydantic import model_serializer
from typing import Any, Dict, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


class CreateSlackChannelEndpointDtoContext2TypedDict(TypedDict):
    r"""Rich context object with id and optional data"""

    id: str
    data: NotRequired[Dict[str, Any]]
    r"""Optional additional context data"""


class CreateSlackChannelEndpointDtoContext2(BaseModel):
    r"""Rich context object with id and optional data"""

    id: str

    data: Optional[Dict[str, Any]] = None
    r"""Optional additional context data"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["data"])
        serialized = handler(self)
        m = {}

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

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


CreateSlackChannelEndpointDtoContextTypedDict = TypeAliasType(
    "CreateSlackChannelEndpointDtoContextTypedDict",
    Union[CreateSlackChannelEndpointDtoContext2TypedDict, str],
)


CreateSlackChannelEndpointDtoContext = TypeAliasType(
    "CreateSlackChannelEndpointDtoContext",
    Union[CreateSlackChannelEndpointDtoContext2, str],
)


class CreateSlackChannelEndpointDtoType(str, Enum):
    r"""Type of channel endpoint"""

    SLACK_CHANNEL = "slack_channel"


class CreateSlackChannelEndpointDtoTypedDict(TypedDict):
    subscriber_id: str
    r"""The subscriber ID to which the channel endpoint is linked"""
    integration_identifier: str
    r"""The identifier of the integration to use for this channel endpoint."""
    type: CreateSlackChannelEndpointDtoType
    r"""Type of channel endpoint"""
    endpoint: SlackChannelEndpointDtoTypedDict
    r"""Slack channel endpoint data"""
    identifier: NotRequired[str]
    r"""The unique identifier for the channel endpoint. If not provided, one will be generated automatically."""
    context: NotRequired[Dict[str, CreateSlackChannelEndpointDtoContextTypedDict]]
    connection_identifier: NotRequired[str]
    r"""The identifier of the channel connection to use for this channel endpoint."""


class CreateSlackChannelEndpointDto(BaseModel):
    subscriber_id: Annotated[str, pydantic.Field(alias="subscriberId")]
    r"""The subscriber ID to which the channel endpoint is linked"""

    integration_identifier: Annotated[
        str, pydantic.Field(alias="integrationIdentifier")
    ]
    r"""The identifier of the integration to use for this channel endpoint."""

    type: CreateSlackChannelEndpointDtoType
    r"""Type of channel endpoint"""

    endpoint: SlackChannelEndpointDto
    r"""Slack channel endpoint data"""

    identifier: Optional[str] = None
    r"""The unique identifier for the channel endpoint. If not provided, one will be generated automatically."""

    context: Optional[Dict[str, CreateSlackChannelEndpointDtoContext]] = None

    connection_identifier: Annotated[
        Optional[str], pydantic.Field(alias="connectionIdentifier")
    ] = None
    r"""The identifier of the channel connection to use for this channel endpoint."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["identifier", "context", "connectionIdentifier"])
        serialized = handler(self)
        m = {}

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

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


try:
    CreateSlackChannelEndpointDto.model_rebuild()
except NameError:
    pass
