"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
# @generated-id: 50a25e4e336c

from __future__ import annotations
from .mirrorconfig import MirrorConfig, MirrorConfigTypedDict
from mistralai.client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
import pydantic
from pydantic import ConfigDict, model_serializer
from typing import Any, Dict, Union
from typing_extensions import NotRequired, TypeAliasType, TypedDict


InternalMetadataAgentVersionTypedDict = TypeAliasType(
    "InternalMetadataAgentVersionTypedDict", Union[str, int]
)


InternalMetadataAgentVersion = TypeAliasType(
    "InternalMetadataAgentVersion", Union[str, int]
)


class InternalMetadataTypedDict(TypedDict):
    r"""Typed structure for internal metadata."""

    agent_id: NotRequired[Nullable[str]]
    agent_version: NotRequired[Nullable[InternalMetadataAgentVersionTypedDict]]
    mirror_config: NotRequired[Nullable[MirrorConfigTypedDict]]
    science_config: NotRequired[Nullable[Dict[str, Any]]]


class InternalMetadata(BaseModel):
    r"""Typed structure for internal metadata."""

    model_config = ConfigDict(
        populate_by_name=True, arbitrary_types_allowed=True, extra="allow"
    )
    __pydantic_extra__: Dict[str, Any] = pydantic.Field(init=False)

    agent_id: OptionalNullable[str] = UNSET

    agent_version: OptionalNullable[InternalMetadataAgentVersion] = UNSET

    mirror_config: OptionalNullable[MirrorConfig] = UNSET

    science_config: OptionalNullable[Dict[str, Any]] = UNSET

    @property
    def additional_properties(self):
        return self.__pydantic_extra__

    @additional_properties.setter
    def additional_properties(self, value):
        self.__pydantic_extra__ = value  # pyright: ignore[reportIncompatibleVariableOverride]

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            ["agent_id", "agent_version", "mirror_config", "science_config"]
        )
        nullable_fields = set(
            ["agent_id", "agent_version", "mirror_config", "science_config"]
        )
        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))
            serialized.pop(k, serialized.pop(n, None))
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

            if val != UNSET_SENTINEL:
                if (
                    val is not None
                    or k not in optional_fields
                    or is_nullable_and_explicitly_set
                ):
                    m[k] = val
        for k, v in serialized.items():
            m[k] = v

        return m
