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

from __future__ import annotations
from .pushoptiontype import PushOptionType
from codat_bankfeeds.types import BaseModel, UNSET_SENTINEL
import pydantic
from pydantic import model_serializer
from typing import Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class PushOptionChoiceTypedDict(TypedDict):
    description: NotRequired[str]
    r"""A description of the property."""
    display_name: NotRequired[str]
    r"""The property's display name."""
    required: NotRequired[bool]
    r"""The property is required if `True`."""
    type: NotRequired[PushOptionType]
    r"""The option type."""
    value: NotRequired[str]
    r"""Allowed value for field."""


class PushOptionChoice(BaseModel):
    description: Optional[str] = None
    r"""A description of the property."""

    display_name: Annotated[Optional[str], pydantic.Field(alias="displayName")] = None
    r"""The property's display name."""

    required: Optional[bool] = None
    r"""The property is required if `True`."""

    type: Optional[PushOptionType] = None
    r"""The option type."""

    value: Optional[str] = None
    r"""Allowed value for field."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            ["description", "displayName", "required", "type", "value"]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m
