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

from __future__ import annotations
from apideck_unify import models, utils
from apideck_unify.types import BaseModel
from apideck_unify.utils import validate_open_enum
from enum import Enum
from pydantic import field_serializer
from pydantic.functional_validators import PlainValidator
from typing import List, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


FiveTypedDict = TypeAliasType("FiveTypedDict", Union[str, int, float])


Five = TypeAliasType("Five", Union[str, int, float])


ValueTypedDict = TypeAliasType(
    "ValueTypedDict", Union[str, int, float, bool, List[FiveTypedDict]]
)


Value = TypeAliasType("Value", Union[str, int, float, bool, List[Five]])


class OptionType(str, Enum, metaclass=utils.OpenEnumMeta):
    SIMPLE = "simple"


class SimpleFormFieldOptionTypedDict(TypedDict):
    label: str
    option_type: OptionType
    value: NotRequired[ValueTypedDict]


class SimpleFormFieldOption(BaseModel):
    label: str

    option_type: Annotated[OptionType, PlainValidator(validate_open_enum(False))]

    value: Optional[Value] = None

    @field_serializer("option_type")
    def serialize_option_type(self, value):
        if isinstance(value, str):
            try:
                return models.OptionType(value)
            except ValueError:
                return value
        return value
