from __future__ import annotations
from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, TypeVar, cast
from attrs import define as _attrs_define
from ..types import UNSET, Unset
if TYPE_CHECKING:
from ..models.custom_property_schema_select_option import CustomPropertySchemaSelectOption
T = TypeVar("T", bound="CustomPropertySchemaSelectSettings")
[docs]
@_attrs_define
class CustomPropertySchemaSelectSettings:
"""Settings specific to 'Select' and 'MultiSelect' type custom properties."""
options: list[CustomPropertySchemaSelectOption] | None | Unset = UNSET
""" The valid select options. """
[docs]
def to_dict(self) -> dict[str, Any]:
options: list[dict[str, Any]] | None | Unset
if isinstance(self.options, Unset):
options = UNSET
elif isinstance(self.options, list):
options = []
for options_type_0_item_data in self.options:
options_type_0_item = options_type_0_item_data.to_dict()
options.append(options_type_0_item)
else:
options = self.options
field_dict: dict[str, Any] = {}
field_dict.update({})
if options is not UNSET:
field_dict["options"] = options
return field_dict
[docs]
@classmethod
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
from ..models.custom_property_schema_select_option import CustomPropertySchemaSelectOption # noqa: PLC0415
d = dict(src_dict)
def _parse_options(data: object) -> list[CustomPropertySchemaSelectOption] | None | Unset:
if data is None:
return data
if isinstance(data, Unset):
return data
try:
if not isinstance(data, list):
raise TypeError()
options_type_0 = []
_options_type_0 = data
for options_type_0_item_data in _options_type_0:
options_type_0_item = CustomPropertySchemaSelectOption.from_dict(options_type_0_item_data)
options_type_0.append(options_type_0_item)
return options_type_0
except (TypeError, ValueError, AttributeError, KeyError):
pass
return cast(list[CustomPropertySchemaSelectOption] | None | Unset, data)
options = _parse_options(d.pop("options", UNSET))
custom_property_schema_select_settings = cls(
options=options,
)
return custom_property_schema_select_settings