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

from __future__ import annotations
from .elasticsearch_resultsnodeinfo_nodes_nodedata_jvm import (
    ElasticSearchResultsNodeInfoNodesNodeDataJVM,
    ElasticSearchResultsNodeInfoNodesNodeDataJVMTypedDict,
)
from .elasticsearch_resultsnodeinfo_nodes_nodedata_modules import (
    ElasticSearchResultsNodeInfoNodesNodeDataModules,
    ElasticSearchResultsNodeInfoNodesNodeDataModulesTypedDict,
)
from .elasticsearch_resultsnodeinfo_nodes_nodedata_nodesettings import (
    ElasticSearchResultsNodeInfoNodesNodeDataNodeSettings,
    ElasticSearchResultsNodeInfoNodesNodeDataNodeSettingsTypedDict,
)
from .elasticsearch_resultsnodeinfo_nodes_nodedata_os import (
    ElasticSearchResultsNodeInfoNodesNodeDataOS,
    ElasticSearchResultsNodeInfoNodesNodeDataOSTypedDict,
)
from .elasticsearch_resultsnodeinfo_nodes_nodedata_threadpool import (
    ElasticSearchResultsNodeInfoNodesNodeDataThreadPool,
    ElasticSearchResultsNodeInfoNodesNodeDataThreadPoolTypedDict,
)
from censys_platform.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import NotRequired, TypedDict


class ElasticSearchResultsNodeInfoNodesNodeDataTypedDict(TypedDict):
    build_flavor: NotRequired[str]
    build_hash: NotRequired[str]
    build_type: NotRequired[str]
    host: NotRequired[str]
    ingest_processors: NotRequired[Nullable[List[str]]]
    ip: NotRequired[str]
    ip_raw: NotRequired[str]
    jvm: NotRequired[ElasticSearchResultsNodeInfoNodesNodeDataJVMTypedDict]
    modules: NotRequired[
        Nullable[List[ElasticSearchResultsNodeInfoNodesNodeDataModulesTypedDict]]
    ]
    name: NotRequired[str]
    os: NotRequired[ElasticSearchResultsNodeInfoNodesNodeDataOSTypedDict]
    roles: NotRequired[Nullable[List[str]]]
    settings: NotRequired[
        ElasticSearchResultsNodeInfoNodesNodeDataNodeSettingsTypedDict
    ]
    thread_pool_list: NotRequired[
        Nullable[List[ElasticSearchResultsNodeInfoNodesNodeDataThreadPoolTypedDict]]
    ]
    total_indexing_buffer: NotRequired[int]
    version: NotRequired[str]


class ElasticSearchResultsNodeInfoNodesNodeData(BaseModel):
    build_flavor: Optional[str] = None

    build_hash: Optional[str] = None

    build_type: Optional[str] = None

    host: Optional[str] = None

    ingest_processors: OptionalNullable[List[str]] = UNSET

    ip: Optional[str] = None

    ip_raw: Optional[str] = None

    jvm: Optional[ElasticSearchResultsNodeInfoNodesNodeDataJVM] = None

    modules: OptionalNullable[
        List[ElasticSearchResultsNodeInfoNodesNodeDataModules]
    ] = UNSET

    name: Optional[str] = None

    os: Optional[ElasticSearchResultsNodeInfoNodesNodeDataOS] = None

    roles: OptionalNullable[List[str]] = UNSET

    settings: Optional[ElasticSearchResultsNodeInfoNodesNodeDataNodeSettings] = None

    thread_pool_list: OptionalNullable[
        List[ElasticSearchResultsNodeInfoNodesNodeDataThreadPool]
    ] = UNSET

    total_indexing_buffer: Optional[int] = None

    version: Optional[str] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "build_flavor",
            "build_hash",
            "build_type",
            "host",
            "ingest_processors",
            "ip",
            "ip_raw",
            "jvm",
            "modules",
            "name",
            "os",
            "roles",
            "settings",
            "thread_pool_list",
            "total_indexing_buffer",
            "version",
        ]
        nullable_fields = ["ingest_processors", "modules", "roles", "thread_pool_list"]
        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
