from __future__ import annotations
import datetime
from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, TypeVar, cast
from attrs import define as _attrs_define
from ..models.blast_status import BlastStatus
from ..types import UNSET, Unset
if TYPE_CHECKING:
from ..models.custom_property_value_model import CustomPropertyValueModel
T = TypeVar("T", bound="BlastModel")
[docs]
@_attrs_define
class BlastModel:
"""A collection of holes designed to be detonated together."""
blast_name: str
""" The name of this blast. """
blast_id: int | Unset = UNSET
""" The unique identifier of this blast. """
status: BlastStatus | Unset = UNSET
fired_time: datetime.datetime | None | Unset = UNSET
""" When this blast was fired (UTC). Null indicates the blast has not been fired. """
abandoned_time: datetime.datetime | None | Unset = UNSET
""" When this blast was abandoned (UTC). Null indicates the blast has not been abandoned. """
etag: None | str | Unset = UNSET
""" The blast's current ETag. """
custom_properties: list[CustomPropertyValueModel] | None | Unset = UNSET
""" The custom property values of this blast. """
[docs]
def to_dict(self) -> dict[str, Any]:
blast_name = self.blast_name
blast_id = self.blast_id
status: str | Unset = UNSET
if not isinstance(self.status, Unset):
status = self.status.value
fired_time: None | str | Unset
if isinstance(self.fired_time, Unset):
fired_time = UNSET
elif isinstance(self.fired_time, datetime.datetime):
fired_time = self.fired_time.isoformat()
else:
fired_time = self.fired_time
abandoned_time: None | str | Unset
if isinstance(self.abandoned_time, Unset):
abandoned_time = UNSET
elif isinstance(self.abandoned_time, datetime.datetime):
abandoned_time = self.abandoned_time.isoformat()
else:
abandoned_time = self.abandoned_time
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(
{
"blastName": blast_name,
}
)
if blast_id is not UNSET:
field_dict["blastId"] = blast_id
if status is not UNSET:
field_dict["status"] = status
if fired_time is not UNSET:
field_dict["firedTime"] = fired_time
if abandoned_time is not UNSET:
field_dict["abandonedTime"] = abandoned_time
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
d = dict(src_dict)
blast_name = d.pop("blastName")
blast_id = d.pop("blastId", UNSET)
_status = d.pop("status", UNSET)
status: BlastStatus | Unset
if isinstance(_status, Unset):
status = UNSET
else:
status = BlastStatus(_status)
def _parse_fired_time(data: object) -> datetime.datetime | None | Unset:
if data is None:
return data
if isinstance(data, Unset):
return data
try:
if not isinstance(data, str):
raise TypeError()
fired_time_type_0 = datetime.datetime.fromisoformat(data)
return fired_time_type_0
except (TypeError, ValueError, AttributeError, KeyError):
pass
return cast(datetime.datetime | None | Unset, data)
fired_time = _parse_fired_time(d.pop("firedTime", UNSET))
def _parse_abandoned_time(data: object) -> datetime.datetime | None | Unset:
if data is None:
return data
if isinstance(data, Unset):
return data
try:
if not isinstance(data, str):
raise TypeError()
abandoned_time_type_0 = datetime.datetime.fromisoformat(data)
return abandoned_time_type_0
except (TypeError, ValueError, AttributeError, KeyError):
pass
return cast(datetime.datetime | None | Unset, data)
abandoned_time = _parse_abandoned_time(d.pop("abandonedTime", 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))
blast_model = cls(
blast_name=blast_name,
blast_id=blast_id,
status=status,
fired_time=fired_time,
abandoned_time=abandoned_time,
etag=etag,
custom_properties=custom_properties,
)
return blast_model