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_value_model import CustomPropertyValueModel
from ..models.hole_geometry import HoleGeometry
T = TypeVar("T", bound="HoleModel")
[docs]
@_attrs_define
class HoleModel:
"""Details of a hole."""
hole_id: int | Unset = UNSET
""" The unique identifier of this hole. """
blast_id: int | Unset = UNSET
""" The ID of the blast this hole belongs to. """
hole_name: None | str | Unset = UNSET
""" The name of this hole. """
row: None | str | Unset = UNSET
""" The row this hole sits in. Can be null. """
echelon: int | None | Unset = UNSET
""" The echelon this hole sits in. Can be null. """
status: None | str | Unset = UNSET
""" The status of the hole. """
design: HoleGeometry | None | Unset = UNSET
""" The hole geometry as designed. """
last_known: HoleGeometry | None | Unset = UNSET
""" The hole geometry according to most recent data. """
etag: None | str | Unset = UNSET
""" The hole's current ETag. """
custom_properties: list[CustomPropertyValueModel] | None | Unset = UNSET
""" The custom property values of this hole. """
[docs]
def to_dict(self) -> dict[str, Any]:
from ..models.hole_geometry import HoleGeometry # noqa: PLC0415
hole_id = self.hole_id
blast_id = self.blast_id
hole_name: None | str | Unset
if isinstance(self.hole_name, Unset):
hole_name = UNSET
else:
hole_name = self.hole_name
row: None | str | Unset
if isinstance(self.row, Unset):
row = UNSET
else:
row = self.row
echelon: int | None | Unset
if isinstance(self.echelon, Unset):
echelon = UNSET
else:
echelon = self.echelon
status: None | str | Unset
if isinstance(self.status, Unset):
status = UNSET
else:
status = self.status
design: dict[str, Any] | None | Unset
if isinstance(self.design, Unset):
design = UNSET
elif isinstance(self.design, HoleGeometry):
design = self.design.to_dict()
else:
design = self.design
last_known: dict[str, Any] | None | Unset
if isinstance(self.last_known, Unset):
last_known = UNSET
elif isinstance(self.last_known, HoleGeometry):
last_known = self.last_known.to_dict()
else:
last_known = self.last_known
etag: None | str | Unset
if isinstance(self.etag, Unset):
etag = UNSET
else:
etag = self.etag
custom_properties: list[dict[str, Any]] | None | Unset
if isinstance(self.custom_properties, Unset):
custom_properties = UNSET
elif isinstance(self.custom_properties, list):
custom_properties = []
for custom_properties_type_0_item_data in self.custom_properties:
custom_properties_type_0_item = custom_properties_type_0_item_data.to_dict()
custom_properties.append(custom_properties_type_0_item)
else:
custom_properties = self.custom_properties
field_dict: dict[str, Any] = {}
field_dict.update({})
if hole_id is not UNSET:
field_dict["holeId"] = hole_id
if blast_id is not UNSET:
field_dict["blastId"] = blast_id
if hole_name is not UNSET:
field_dict["holeName"] = hole_name
if row is not UNSET:
field_dict["row"] = row
if echelon is not UNSET:
field_dict["echelon"] = echelon
if status is not UNSET:
field_dict["status"] = status
if design is not UNSET:
field_dict["design"] = design
if last_known is not UNSET:
field_dict["lastKnown"] = last_known
if etag is not UNSET:
field_dict["etag"] = etag
if custom_properties is not UNSET:
field_dict["customProperties"] = custom_properties
return field_dict
[docs]
@classmethod
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
from ..models.custom_property_value_model import CustomPropertyValueModel # noqa: PLC0415
from ..models.hole_geometry import HoleGeometry # noqa: PLC0415
d = dict(src_dict)
hole_id = d.pop("holeId", UNSET)
blast_id = d.pop("blastId", UNSET)
def _parse_hole_name(data: object) -> None | str | Unset:
if data is None:
return data
if isinstance(data, Unset):
return data
return cast(None | str | Unset, data)
hole_name = _parse_hole_name(d.pop("holeName", UNSET))
def _parse_row(data: object) -> None | str | Unset:
if data is None:
return data
if isinstance(data, Unset):
return data
return cast(None | str | Unset, data)
row = _parse_row(d.pop("row", UNSET))
def _parse_echelon(data: object) -> int | None | Unset:
if data is None:
return data
if isinstance(data, Unset):
return data
return cast(int | None | Unset, data)
echelon = _parse_echelon(d.pop("echelon", UNSET))
def _parse_status(data: object) -> None | str | Unset:
if data is None:
return data
if isinstance(data, Unset):
return data
return cast(None | str | Unset, data)
status = _parse_status(d.pop("status", UNSET))
def _parse_design(data: object) -> HoleGeometry | None | Unset:
if data is None:
return data
if isinstance(data, Unset):
return data
try:
if not isinstance(data, dict):
raise TypeError()
design_type_0 = HoleGeometry.from_dict(data)
return design_type_0
except (TypeError, ValueError, AttributeError, KeyError):
pass
return cast(HoleGeometry | None | Unset, data)
design = _parse_design(d.pop("design", UNSET))
def _parse_last_known(data: object) -> HoleGeometry | None | Unset:
if data is None:
return data
if isinstance(data, Unset):
return data
try:
if not isinstance(data, dict):
raise TypeError()
last_known_type_0 = HoleGeometry.from_dict(data)
return last_known_type_0
except (TypeError, ValueError, AttributeError, KeyError):
pass
return cast(HoleGeometry | None | Unset, data)
last_known = _parse_last_known(d.pop("lastKnown", UNSET))
def _parse_etag(data: object) -> None | str | Unset:
if data is None:
return data
if isinstance(data, Unset):
return data
return cast(None | str | Unset, data)
etag = _parse_etag(d.pop("etag", UNSET))
def _parse_custom_properties(data: object) -> list[CustomPropertyValueModel] | None | Unset:
if data is None:
return data
if isinstance(data, Unset):
return data
try:
if not isinstance(data, list):
raise TypeError()
custom_properties_type_0 = []
_custom_properties_type_0 = data
for custom_properties_type_0_item_data in _custom_properties_type_0:
custom_properties_type_0_item = CustomPropertyValueModel.from_dict(
custom_properties_type_0_item_data
)
custom_properties_type_0.append(custom_properties_type_0_item)
return custom_properties_type_0
except (TypeError, ValueError, AttributeError, KeyError):
pass
return cast(list[CustomPropertyValueModel] | None | Unset, data)
custom_properties = _parse_custom_properties(d.pop("customProperties", UNSET))
hole_model = cls(
hole_id=hole_id,
blast_id=blast_id,
hole_name=hole_name,
row=row,
echelon=echelon,
status=status,
design=design,
last_known=last_known,
etag=etag,
custom_properties=custom_properties,
)
return hole_model