"""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,
)
from pydantic import model_serializer
from typing import Optional
from typing_extensions import 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."""
    config: AWSSQSConfigTypedDict
    credentials: AWSSQSCredentialsTypedDict
    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."""

    config: AWSSQSConfig

    credentials: AWSSQSCredentials

    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 = ["target", "target_url"]
        nullable_fields = ["disabled_at", "target_url"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

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

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m
