Source code for maptekblastlogic.models.custom_property_value_model

from __future__ import annotations

from collections.abc import Mapping
from typing import Any, TypeVar, cast

from attrs import define as _attrs_define

from ..types import UNSET, Unset

T = TypeVar("T", bound="CustomPropertyValueModel")


[docs] @_attrs_define class CustomPropertyValueModel: """Describes a value assigned to a custom property for a blast/hole.""" custom_property_id: str """ The ID of the custom property this value belongs to. """ entity_id: int """ The ID of the blast/hole's this value belongs to. """ etag: str """ The current etag of the entity this value belongs to. """ boolean_value: bool | None | Unset = UNSET """ The value of this custom property when it's of type 'Boolean'. """ string_value: None | str | Unset = UNSET """ The value of this custom property when it's of type 'String'. """ float_value: float | None | Unset = UNSET """ The value of this custom property when it's of type 'Float'. Expressed in the unit of measurement indicated by the custom property schema. """ float_range_lower_value: float | None | Unset = UNSET """ The lower value of this custom property when it's of type 'FloatRange'. Expressed in the unit of measurement indicated by the custom property schema. """ float_range_upper_value: float | None | Unset = UNSET """ The upper value of this custom property when it's of type 'FloatRange'. Expressed in the unit of measurement indicated by the custom property schema. """ select_value: None | str | Unset = UNSET """ The selected value of this custom property when it's of type 'Select'. """ multi_select_values: list[str] | None | Unset = UNSET """ The selected values of this custom property when it's of type 'MultiSelect'. """
[docs] def to_dict(self) -> dict[str, Any]: custom_property_id = self.custom_property_id entity_id = self.entity_id etag = self.etag boolean_value: bool | None | Unset if isinstance(self.boolean_value, Unset): boolean_value = UNSET else: boolean_value = self.boolean_value string_value: None | str | Unset if isinstance(self.string_value, Unset): string_value = UNSET else: string_value = self.string_value float_value: float | None | Unset if isinstance(self.float_value, Unset): float_value = UNSET else: float_value = self.float_value float_range_lower_value: float | None | Unset if isinstance(self.float_range_lower_value, Unset): float_range_lower_value = UNSET else: float_range_lower_value = self.float_range_lower_value float_range_upper_value: float | None | Unset if isinstance(self.float_range_upper_value, Unset): float_range_upper_value = UNSET else: float_range_upper_value = self.float_range_upper_value select_value: None | str | Unset if isinstance(self.select_value, Unset): select_value = UNSET else: select_value = self.select_value multi_select_values: list[str] | None | Unset if isinstance(self.multi_select_values, Unset): multi_select_values = UNSET elif isinstance(self.multi_select_values, list): multi_select_values = self.multi_select_values else: multi_select_values = self.multi_select_values field_dict: dict[str, Any] = {} field_dict.update( { "customPropertyId": custom_property_id, "entityId": entity_id, "etag": etag, } ) if boolean_value is not UNSET: field_dict["booleanValue"] = boolean_value if string_value is not UNSET: field_dict["stringValue"] = string_value if float_value is not UNSET: field_dict["floatValue"] = float_value if float_range_lower_value is not UNSET: field_dict["floatRangeLowerValue"] = float_range_lower_value if float_range_upper_value is not UNSET: field_dict["floatRangeUpperValue"] = float_range_upper_value if select_value is not UNSET: field_dict["selectValue"] = select_value if multi_select_values is not UNSET: field_dict["multiSelectValues"] = multi_select_values return field_dict
[docs] @classmethod def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: d = dict(src_dict) custom_property_id = d.pop("customPropertyId") entity_id = d.pop("entityId") etag = d.pop("etag") def _parse_boolean_value(data: object) -> bool | None | Unset: if data is None: return data if isinstance(data, Unset): return data return cast(bool | None | Unset, data) boolean_value = _parse_boolean_value(d.pop("booleanValue", UNSET)) def _parse_string_value(data: object) -> None | str | Unset: if data is None: return data if isinstance(data, Unset): return data return cast(None | str | Unset, data) string_value = _parse_string_value(d.pop("stringValue", UNSET)) def _parse_float_value(data: object) -> float | None | Unset: if data is None: return data if isinstance(data, Unset): return data return cast(float | None | Unset, data) float_value = _parse_float_value(d.pop("floatValue", UNSET)) def _parse_float_range_lower_value(data: object) -> float | None | Unset: if data is None: return data if isinstance(data, Unset): return data return cast(float | None | Unset, data) float_range_lower_value = _parse_float_range_lower_value(d.pop("floatRangeLowerValue", UNSET)) def _parse_float_range_upper_value(data: object) -> float | None | Unset: if data is None: return data if isinstance(data, Unset): return data return cast(float | None | Unset, data) float_range_upper_value = _parse_float_range_upper_value(d.pop("floatRangeUpperValue", UNSET)) def _parse_select_value(data: object) -> None | str | Unset: if data is None: return data if isinstance(data, Unset): return data return cast(None | str | Unset, data) select_value = _parse_select_value(d.pop("selectValue", UNSET)) def _parse_multi_select_values(data: object) -> list[str] | None | Unset: if data is None: return data if isinstance(data, Unset): return data try: if not isinstance(data, list): raise TypeError() multi_select_values_type_0 = cast(list[str], data) return multi_select_values_type_0 except (TypeError, ValueError, AttributeError, KeyError): pass return cast(list[str] | None | Unset, data) multi_select_values = _parse_multi_select_values(d.pop("multiSelectValues", UNSET)) custom_property_value_model = cls( custom_property_id=custom_property_id, entity_id=entity_id, etag=etag, boolean_value=boolean_value, string_value=string_value, float_value=float_value, float_range_lower_value=float_range_lower_value, float_range_upper_value=float_range_upper_value, select_value=select_value, multi_select_values=multi_select_values, ) return custom_property_value_model