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

from __future__ import annotations
from .createmanuallineitemrequest import (
    CreateManualLineItemRequest,
    CreateManualLineItemRequestTypedDict,
)
from paygentic_sdk.types import BaseModel, UNSET_SENTINEL
from paygentic_sdk.utils import FieldMetadata, HeaderMetadata, RequestMetadata
import pydantic
from pydantic import model_serializer
from typing import Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class CreateLineItemRequestTypedDict(TypedDict):
    create_manual_line_item_request: CreateManualLineItemRequestTypedDict
    idempotency_key_param: NotRequired[str]
    r"""Optional idempotency key. If provided, duplicate requests with the same key return the previously created item."""


class CreateLineItemRequest(BaseModel):
    create_manual_line_item_request: Annotated[
        CreateManualLineItemRequest,
        FieldMetadata(request=RequestMetadata(media_type="application/json")),
    ]

    idempotency_key_param: Annotated[
        Optional[str],
        pydantic.Field(alias="Idempotency-Key"),
        FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
    ] = None
    r"""Optional idempotency key. If provided, duplicate requests with the same key return the previously created item."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["Idempotency-Key_param"])
        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
