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

from __future__ import annotations
import pydantic
from pydantic import model_serializer
from squadcast.types import BaseModel, UNSET_SENTINEL
from typing import Any, List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class EntityTypedDict(TypedDict):
    pass


class Entity(BaseModel):
    pass


class V3WorkflowsCreateWorkflowFilterTypedDict(TypedDict):
    type: NotRequired[str]
    key: NotRequired[str]
    value: NotRequired[Any]
    fields: NotRequired[V3WorkflowsCreateWorkflowFilterTypedDict]
    children: NotRequired[List[V3WorkflowsCreateWorkflowFilterTypedDict]]
    label: NotRequired[str]
    entity: NotRequired[EntityTypedDict]
    filter_type: NotRequired[str]


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

    key: Optional[str] = None

    value: Optional[Any] = None

    fields: Optional[V3WorkflowsCreateWorkflowFilter] = None

    children: Optional[List[V3WorkflowsCreateWorkflowFilter]] = None

    label: Optional[str] = None

    entity: Optional[Entity] = None

    filter_type: Annotated[Optional[str], pydantic.Field(alias="filterType")] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "type",
                "key",
                "value",
                "fields",
                "children",
                "label",
                "entity",
                "filterType",
            ]
        )
        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


try:
    V3WorkflowsCreateWorkflowFilter.model_rebuild()
except NameError:
    pass
