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 ..models.custom_property_type import CustomPropertyType
from ..types import UNSET, Unset
if TYPE_CHECKING:
from ..models.custom_property_schema_float_range_settings import CustomPropertySchemaFloatRangeSettings
from ..models.custom_property_schema_float_settings import CustomPropertySchemaFloatSettings
from ..models.custom_property_schema_select_settings import CustomPropertySchemaSelectSettings
from ..models.custom_property_schema_string_settings import CustomPropertySchemaStringSettings
T = TypeVar("T", bound="CustomPropertySchemaModel")
[docs]
@_attrs_define
class CustomPropertySchemaModel:
"""Describes a user defined property. Editable from BlastLogic Desktop."""
custom_property_id: None | str | Unset = UNSET
""" The unique identifier of this custom property. """
label: None | str | Unset = UNSET
""" The user-friendly name of this custom property. """
type_: CustomPropertyType | Unset = UNSET
description: None | str | Unset = UNSET
""" The description of this custom property. """
is_required: bool | Unset = UNSET
""" Whether this custom property requires a value. """
string_settings: CustomPropertySchemaStringSettings | None | Unset = UNSET
""" Settings specific to 'String' type custom properties. """
float_settings: CustomPropertySchemaFloatSettings | None | Unset = UNSET
""" Settings specific to 'Float' type custom properties. """
float_range_settings: CustomPropertySchemaFloatRangeSettings | None | Unset = UNSET
""" Settings specific to 'FloatRange' type custom properties. """
select_settings: CustomPropertySchemaSelectSettings | None | Unset = UNSET
""" Settings specific to 'Select' and 'MultiSelect' type custom properties. """
[docs]
def to_dict(self) -> dict[str, Any]:
from ..models.custom_property_schema_float_range_settings import (
CustomPropertySchemaFloatRangeSettings, # noqa: PLC0415
)
from ..models.custom_property_schema_float_settings import CustomPropertySchemaFloatSettings # noqa: PLC0415
from ..models.custom_property_schema_select_settings import CustomPropertySchemaSelectSettings # noqa: PLC0415
from ..models.custom_property_schema_string_settings import CustomPropertySchemaStringSettings # noqa: PLC0415
custom_property_id: None | str | Unset
if isinstance(self.custom_property_id, Unset):
custom_property_id = UNSET
else:
custom_property_id = self.custom_property_id
label: None | str | Unset
if isinstance(self.label, Unset):
label = UNSET
else:
label = self.label
type_: str | Unset = UNSET
if not isinstance(self.type_, Unset):
type_ = self.type_.value
description: None | str | Unset
if isinstance(self.description, Unset):
description = UNSET
else:
description = self.description
is_required = self.is_required
string_settings: dict[str, Any] | None | Unset
if isinstance(self.string_settings, Unset):
string_settings = UNSET
elif isinstance(self.string_settings, CustomPropertySchemaStringSettings):
string_settings = self.string_settings.to_dict()
else:
string_settings = self.string_settings
float_settings: dict[str, Any] | None | Unset
if isinstance(self.float_settings, Unset):
float_settings = UNSET
elif isinstance(self.float_settings, CustomPropertySchemaFloatSettings):
float_settings = self.float_settings.to_dict()
else:
float_settings = self.float_settings
float_range_settings: dict[str, Any] | None | Unset
if isinstance(self.float_range_settings, Unset):
float_range_settings = UNSET
elif isinstance(self.float_range_settings, CustomPropertySchemaFloatRangeSettings):
float_range_settings = self.float_range_settings.to_dict()
else:
float_range_settings = self.float_range_settings
select_settings: dict[str, Any] | None | Unset
if isinstance(self.select_settings, Unset):
select_settings = UNSET
elif isinstance(self.select_settings, CustomPropertySchemaSelectSettings):
select_settings = self.select_settings.to_dict()
else:
select_settings = self.select_settings
field_dict: dict[str, Any] = {}
field_dict.update({})
if custom_property_id is not UNSET:
field_dict["customPropertyId"] = custom_property_id
if label is not UNSET:
field_dict["label"] = label
if type_ is not UNSET:
field_dict["type"] = type_
if description is not UNSET:
field_dict["description"] = description
if is_required is not UNSET:
field_dict["isRequired"] = is_required
if string_settings is not UNSET:
field_dict["stringSettings"] = string_settings
if float_settings is not UNSET:
field_dict["floatSettings"] = float_settings
if float_range_settings is not UNSET:
field_dict["floatRangeSettings"] = float_range_settings
if select_settings is not UNSET:
field_dict["selectSettings"] = select_settings
return field_dict
[docs]
@classmethod
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
from ..models.custom_property_schema_float_range_settings import (
CustomPropertySchemaFloatRangeSettings, # noqa: PLC0415
)
from ..models.custom_property_schema_float_settings import CustomPropertySchemaFloatSettings # noqa: PLC0415
from ..models.custom_property_schema_select_settings import CustomPropertySchemaSelectSettings # noqa: PLC0415
from ..models.custom_property_schema_string_settings import CustomPropertySchemaStringSettings # noqa: PLC0415
d = dict(src_dict)
def _parse_custom_property_id(data: object) -> None | str | Unset:
if data is None:
return data
if isinstance(data, Unset):
return data
return cast(None | str | Unset, data)
custom_property_id = _parse_custom_property_id(d.pop("customPropertyId", UNSET))
def _parse_label(data: object) -> None | str | Unset:
if data is None:
return data
if isinstance(data, Unset):
return data
return cast(None | str | Unset, data)
label = _parse_label(d.pop("label", UNSET))
_type_ = d.pop("type", UNSET)
type_: CustomPropertyType | Unset
if isinstance(_type_, Unset):
type_ = UNSET
else:
type_ = CustomPropertyType(_type_)
def _parse_description(data: object) -> None | str | Unset:
if data is None:
return data
if isinstance(data, Unset):
return data
return cast(None | str | Unset, data)
description = _parse_description(d.pop("description", UNSET))
is_required = d.pop("isRequired", UNSET)
def _parse_string_settings(data: object) -> CustomPropertySchemaStringSettings | None | Unset:
if data is None:
return data
if isinstance(data, Unset):
return data
try:
if not isinstance(data, dict):
raise TypeError()
string_settings_type_0 = CustomPropertySchemaStringSettings.from_dict(data)
return string_settings_type_0
except (TypeError, ValueError, AttributeError, KeyError):
pass
return cast(CustomPropertySchemaStringSettings | None | Unset, data)
string_settings = _parse_string_settings(d.pop("stringSettings", UNSET))
def _parse_float_settings(data: object) -> CustomPropertySchemaFloatSettings | None | Unset:
if data is None:
return data
if isinstance(data, Unset):
return data
try:
if not isinstance(data, dict):
raise TypeError()
float_settings_type_0 = CustomPropertySchemaFloatSettings.from_dict(data)
return float_settings_type_0
except (TypeError, ValueError, AttributeError, KeyError):
pass
return cast(CustomPropertySchemaFloatSettings | None | Unset, data)
float_settings = _parse_float_settings(d.pop("floatSettings", UNSET))
def _parse_float_range_settings(data: object) -> CustomPropertySchemaFloatRangeSettings | None | Unset:
if data is None:
return data
if isinstance(data, Unset):
return data
try:
if not isinstance(data, dict):
raise TypeError()
float_range_settings_type_0 = CustomPropertySchemaFloatRangeSettings.from_dict(data)
return float_range_settings_type_0
except (TypeError, ValueError, AttributeError, KeyError):
pass
return cast(CustomPropertySchemaFloatRangeSettings | None | Unset, data)
float_range_settings = _parse_float_range_settings(d.pop("floatRangeSettings", UNSET))
def _parse_select_settings(data: object) -> CustomPropertySchemaSelectSettings | None | Unset:
if data is None:
return data
if isinstance(data, Unset):
return data
try:
if not isinstance(data, dict):
raise TypeError()
select_settings_type_0 = CustomPropertySchemaSelectSettings.from_dict(data)
return select_settings_type_0
except (TypeError, ValueError, AttributeError, KeyError):
pass
return cast(CustomPropertySchemaSelectSettings | None | Unset, data)
select_settings = _parse_select_settings(d.pop("selectSettings", UNSET))
custom_property_schema_model = cls(
custom_property_id=custom_property_id,
label=label,
type_=type_,
description=description,
is_required=is_required,
string_settings=string_settings,
float_settings=float_settings,
float_range_settings=float_range_settings,
select_settings=select_settings,
)
return custom_property_schema_model