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

from __future__ import annotations
from .simpleformfieldoption import SimpleFormFieldOption, SimpleFormFieldOptionTypedDict
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
from typing_extensions import Annotated, NotRequired, TypedDict


class FormFieldOptionGroupOptionType(str, Enum, metaclass=utils.OpenEnumMeta):
    GROUP = "group"


class FormFieldOptionGroupTypedDict(TypedDict):
    label: str
    options: List[SimpleFormFieldOptionTypedDict]
    option_type: FormFieldOptionGroupOptionType
    id: NotRequired[str]


class FormFieldOptionGroup(BaseModel):
    label: str

    options: List[SimpleFormFieldOption]

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

    id: Optional[str] = None

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