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

from __future__ import annotations
from .destinationtype import DestinationType
from outpost_sdk.types import BaseModel, UNSET_SENTINEL
from outpost_sdk.utils import FieldMetadata, PathParamMetadata, QueryParamMetadata
from pydantic import model_serializer
from typing import List, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


ListTenantDestinationsTypeTypedDict = TypeAliasType(
    "ListTenantDestinationsTypeTypedDict", Union[DestinationType, List[DestinationType]]
)
r"""Filter destinations by type(s). Use bracket notation for multiple values (e.g., `type[0]=webhook&type[1]=aws_sqs`)."""


ListTenantDestinationsType = TypeAliasType(
    "ListTenantDestinationsType", Union[DestinationType, List[DestinationType]]
)
r"""Filter destinations by type(s). Use bracket notation for multiple values (e.g., `type[0]=webhook&type[1]=aws_sqs`)."""


ListTenantDestinationsTopicsTypedDict = TypeAliasType(
    "ListTenantDestinationsTopicsTypedDict", Union[str, List[str]]
)
r"""Filter destinations by supported topic(s). Use bracket notation for multiple values (e.g., `topics[0]=user.created&topics[1]=user.deleted`)."""


ListTenantDestinationsTopics = TypeAliasType(
    "ListTenantDestinationsTopics", Union[str, List[str]]
)
r"""Filter destinations by supported topic(s). Use bracket notation for multiple values (e.g., `topics[0]=user.created&topics[1]=user.deleted`)."""


class ListTenantDestinationsRequestTypedDict(TypedDict):
    tenant_id: str
    r"""The ID of the tenant. Required when using AdminApiKey authentication."""
    type: NotRequired[ListTenantDestinationsTypeTypedDict]
    r"""Filter destinations by type(s). Use bracket notation for multiple values (e.g., `type[0]=webhook&type[1]=aws_sqs`)."""
    topics: NotRequired[ListTenantDestinationsTopicsTypedDict]
    r"""Filter destinations by supported topic(s). Use bracket notation for multiple values (e.g., `topics[0]=user.created&topics[1]=user.deleted`)."""


class ListTenantDestinationsRequest(BaseModel):
    tenant_id: Annotated[
        str, FieldMetadata(path=PathParamMetadata(style="simple", explode=False))
    ]
    r"""The ID of the tenant. Required when using AdminApiKey authentication."""

    type: Annotated[
        Optional[ListTenantDestinationsType],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter destinations by type(s). Use bracket notation for multiple values (e.g., `type[0]=webhook&type[1]=aws_sqs`)."""

    topics: Annotated[
        Optional[ListTenantDestinationsTopics],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter destinations by supported topic(s). Use bracket notation for multiple values (e.g., `topics[0]=user.created&topics[1]=user.deleted`)."""

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