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

from __future__ import annotations
from .destinationschemafield import (
    DestinationSchemaField,
    DestinationSchemaFieldTypedDict,
)
from outpost_sdk.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import NotRequired, TypedDict


class DestinationTypeSchemaTypedDict(TypedDict):
    type: NotRequired[str]
    label: NotRequired[str]
    description: NotRequired[str]
    icon: NotRequired[str]
    r"""SVG icon string."""
    instructions: NotRequired[str]
    r"""Markdown instructions."""
    remote_setup_url: NotRequired[str]
    r"""Some destinations may have Oauth flow or other managed-setup flow that can be triggered with a link. If a `remote_setup_url` is set then the user should be prompted to follow the link to configure the destination.
    See the [building your own UI guide](https://outpost.hookdeck.com/guides/building-your-own-ui.mdx) for recommended UI patterns and wireframes for implementation in your own app.
    """
    config_fields: NotRequired[List[DestinationSchemaFieldTypedDict]]
    r"""Config fields are non-secret values that can be stored and displayed to the user in plain text."""
    credential_fields: NotRequired[List[DestinationSchemaFieldTypedDict]]
    r"""Credential fields are secret values that will be AES encrypted and obfuscated to the user. Some credentials may not be obfuscated; the destination type dictates the obfuscation logic."""


class DestinationTypeSchema(BaseModel):
    type: Optional[str] = None

    label: Optional[str] = None

    description: Optional[str] = None

    icon: Optional[str] = None
    r"""SVG icon string."""

    instructions: Optional[str] = None
    r"""Markdown instructions."""

    remote_setup_url: Optional[str] = None
    r"""Some destinations may have Oauth flow or other managed-setup flow that can be triggered with a link. If a `remote_setup_url` is set then the user should be prompted to follow the link to configure the destination.
    See the [building your own UI guide](https://outpost.hookdeck.com/guides/building-your-own-ui.mdx) for recommended UI patterns and wireframes for implementation in your own app.
    """

    config_fields: Optional[List[DestinationSchemaField]] = None
    r"""Config fields are non-secret values that can be stored and displayed to the user in plain text."""

    credential_fields: Optional[List[DestinationSchemaField]] = None
    r"""Credential fields are secret values that will be AES encrypted and obfuscated to the user. Some credentials may not be obfuscated; the destination type dictates the obfuscation logic."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "type",
                "label",
                "description",
                "icon",
                "instructions",
                "remote_setup_url",
                "config_fields",
                "credential_fields",
            ]
        )
        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
