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

from __future__ import annotations
from gusto_app_integration.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
import pydantic
from pydantic import ConfigDict, model_serializer
from typing import Any, Dict, Optional
from typing_extensions import NotRequired, TypedDict


class MetadataWithOneEntityTypedDict(TypedDict):
    r"""single entity"""

    entity_type: NotRequired[str]
    r"""Name of the entity that the error corresponds to."""
    entity_uuid: NotRequired[str]
    r"""Unique identifier for the entity."""
    valid_from: NotRequired[Nullable[str]]
    valid_up_to: NotRequired[Nullable[str]]
    key: NotRequired[Nullable[str]]
    state: NotRequired[Nullable[str]]


class MetadataWithOneEntity(BaseModel):
    r"""single entity"""

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

    entity_type: Optional[str] = None
    r"""Name of the entity that the error corresponds to."""

    entity_uuid: Optional[str] = None
    r"""Unique identifier for the entity."""

    valid_from: OptionalNullable[str] = UNSET

    valid_up_to: OptionalNullable[str] = UNSET

    key: OptionalNullable[str] = UNSET

    state: OptionalNullable[str] = 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 = [
            "entity_type",
            "entity_uuid",
            "valid_from",
            "valid_up_to",
            "key",
            "state",
        ]
        nullable_fields = ["valid_from", "valid_up_to", "key", "state"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in 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

        for k, v in serialized.items():
            m[k] = v

        return m
