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

from __future__ import annotations
from .languagecode import LanguageCode
from pydantic import model_serializer
from syllable_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from syllable_sdk.utils import FieldMetadata, PathParamMetadata, QueryParamMetadata
from typing_extensions import Annotated, NotRequired, TypedDict


class DirectoryMemberTestExtensionRequestTypedDict(TypedDict):
    member_id: int
    timestamp: str
    r"""Timestamp for test in ISO 8601 format (e.g., 2025-12-04T14:29:39)"""
    language_code: NotRequired[Nullable[LanguageCode]]
    r"""Optional language code for test"""


class DirectoryMemberTestExtensionRequest(BaseModel):
    member_id: Annotated[
        int, FieldMetadata(path=PathParamMetadata(style="simple", explode=False))
    ]

    timestamp: Annotated[
        str, FieldMetadata(query=QueryParamMetadata(style="form", explode=True))
    ]
    r"""Timestamp for test in ISO 8601 format (e.g., 2025-12-04T14:29:39)"""

    language_code: Annotated[
        OptionalNullable[LanguageCode],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Optional language code for test"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["language_code"])
        nullable_fields = set(["language_code"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            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

        return m
