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

from __future__ import annotations
from .awssqsconfig import AWSSQSConfig, AWSSQSConfigTypedDict
from .awssqscredentials import AWSSQSCredentials, AWSSQSCredentialsTypedDict
from .topics_union import TopicsUnion, TopicsUnionTypedDict
from datetime import datetime
from enum import Enum
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 DestinationAWSSQSType(str, Enum):
    r"""Type of the destination."""

    AWS_SQS = "aws_sqs"


class DestinationAWSSQSTypedDict(TypedDict):
    id: str
    r"""Control plane generated ID or user provided ID for the destination."""
    type: DestinationAWSSQSType
    r"""Type of the destination."""
    topics: TopicsUnionTypedDict
    r"""\"*\" or an array of enabled topics."""
    disabled_at: Nullable[datetime]
    r"""ISO Date when the destination was disabled, or null if enabled."""
    created_at: datetime
    r"""ISO Date when the destination was created."""
    updated_at: datetime
    r"""ISO Date when the destination was last updated."""
    config: AWSSQSConfigTypedDict
    credentials: AWSSQSCredentialsTypedDict
    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 `{}`.

    """
    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."""
    target: NotRequired[str]
    r"""A human-readable representation of the destination target (SQS queue name). Read-only."""
    target_url: NotRequired[Nullable[str]]
    r"""A URL link to the destination target (AWS Console link to the queue). Read-only."""


class DestinationAWSSQS(BaseModel):
    id: str
    r"""Control plane generated ID or user provided ID for the destination."""

    type: DestinationAWSSQSType
    r"""Type of the destination."""

    topics: TopicsUnion
    r"""\"*\" or an array of enabled topics."""

    disabled_at: Nullable[datetime]
    r"""ISO Date when the destination was disabled, or null if enabled."""

    created_at: datetime
    r"""ISO Date when the destination was created."""

    updated_at: datetime
    r"""ISO Date when the destination was last updated."""

    config: AWSSQSConfig

    credentials: AWSSQSCredentials

    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 `{}`.

    """

    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."""

    target: Optional[str] = None
    r"""A human-readable representation of the destination target (SQS queue name). Read-only."""

    target_url: OptionalNullable[str] = UNSET
    r"""A URL link to the destination target (AWS Console link to the queue). Read-only."""

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