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

from __future__ import annotations
from enum import Enum
from outpost_sdk.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Optional
from typing_extensions import NotRequired, TypedDict


class DestinationSchemaFieldType(str, Enum):
    TEXT = "text"
    CHECKBOX = "checkbox"
    KEY_VALUE_MAP = "key_value_map"


class DestinationSchemaFieldTypedDict(TypedDict):
    type: DestinationSchemaFieldType
    required: bool
    label: NotRequired[str]
    description: NotRequired[str]
    sensitive: NotRequired[bool]
    r"""Indicates if the field contains sensitive information."""
    default: NotRequired[str]
    r"""Default value for the field."""
    minlength: NotRequired[int]
    r"""Minimum length for a text input."""
    maxlength: NotRequired[int]
    r"""Maximum length for a text input."""
    pattern: NotRequired[str]
    r"""Regex pattern for validation (compatible with HTML5 pattern attribute)."""


class DestinationSchemaField(BaseModel):
    type: DestinationSchemaFieldType

    required: bool

    label: Optional[str] = None

    description: Optional[str] = None

    sensitive: Optional[bool] = None
    r"""Indicates if the field contains sensitive information."""

    default: Optional[str] = None
    r"""Default value for the field."""

    minlength: Optional[int] = None
    r"""Minimum length for a text input."""

    maxlength: Optional[int] = None
    r"""Maximum length for a text input."""

    pattern: Optional[str] = None
    r"""Regex pattern for validation (compatible with HTML5 pattern attribute)."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "label",
                "description",
                "sensitive",
                "default",
                "minlength",
                "maxlength",
                "pattern",
            ]
        )
        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
