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

from __future__ import annotations
from .azureservicebusconfig import AzureServiceBusConfig, AzureServiceBusConfigTypedDict
from .azureservicebuscredentials import (
    AzureServiceBusCredentials,
    AzureServiceBusCredentialsTypedDict,
)
from .topics_union import TopicsUnion, TopicsUnionTypedDict
from outpost_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
import pydantic
from pydantic import model_serializer
from typing import Any, Dict, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class DestinationUpdateAzureServiceBusTypedDict(TypedDict):
    topics: NotRequired[TopicsUnionTypedDict]
    r"""\"*\" or an array of enabled topics."""
    filter_: NotRequired[Nullable[Dict[str, Any]]]
    r"""Optional JSON schema filter for event matching. Events must match this filter to be delivered to this destination.
    Supports operators: $eq, $neq, $gt, $gte, $lt, $lte, $in, $nin, $startsWith, $endsWith, $exist, $or, $and, $not.
    If null or empty, all events matching the topic filter will be delivered.
    To remove an existing filter when updating a destination, set filter to an empty object `{}`.

    """
    config: NotRequired[AzureServiceBusConfigTypedDict]
    credentials: NotRequired[AzureServiceBusCredentialsTypedDict]
    delivery_metadata: NotRequired[Nullable[Dict[str, str]]]
    r"""Static key-value pairs merged into event metadata on every attempt."""
    metadata: NotRequired[Nullable[Dict[str, str]]]
    r"""Arbitrary contextual information stored with the destination."""


class DestinationUpdateAzureServiceBus(BaseModel):
    topics: Optional[TopicsUnion] = None
    r"""\"*\" or an array of enabled topics."""

    filter_: Annotated[
        OptionalNullable[Dict[str, Any]], pydantic.Field(alias="filter")
    ] = UNSET
    r"""Optional JSON schema filter for event matching. Events must match this filter to be delivered to this destination.
    Supports operators: $eq, $neq, $gt, $gte, $lt, $lte, $in, $nin, $startsWith, $endsWith, $exist, $or, $and, $not.
    If null or empty, all events matching the topic filter will be delivered.
    To remove an existing filter when updating a destination, set filter to an empty object `{}`.

    """

    config: Optional[AzureServiceBusConfig] = None

    credentials: Optional[AzureServiceBusCredentials] = None

    delivery_metadata: OptionalNullable[Dict[str, str]] = UNSET
    r"""Static key-value pairs merged into event metadata on every attempt."""

    metadata: OptionalNullable[Dict[str, str]] = UNSET
    r"""Arbitrary contextual information stored with the destination."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "topics",
                "filter",
                "config",
                "credentials",
                "delivery_metadata",
                "metadata",
            ]
        )
        nullable_fields = set(["filter", "delivery_metadata", "metadata"])
        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:
    DestinationUpdateAzureServiceBus.model_rebuild()
except NameError:
    pass
