from __future__ import annotations
import datetime
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="LoadingTruckModel")
[docs]
@_attrs_define
class LoadingTruckModel:
"""A truck used to load blast products into holes."""
loading_truck_id: int | Unset = UNSET
""" The unique identifier of this loading truck. """
etag: None | str | Unset = UNSET
""" The loading truck's current ETag. Ignored when creating and editing. """
created_by: None | str | Unset = UNSET
""" Username of the person who created this loading truck. Ignored when creating and editing. """
created_time: datetime.datetime | None | Unset = UNSET
""" When this loading truck was last updated (UTC). Ignored when creating and editing. """
last_modified_by: None | str | Unset = UNSET
""" Username of the person who last updated this loading truck. Ignored when creating and editing. """
last_modified_time: datetime.datetime | None | Unset = UNSET
""" When this loading truck was last updated (UTC). Ignored when creating and editing. """
name: None | str | Unset = UNSET
""" The name of this loading truck. """
active: bool | Unset = UNSET
""" Whether this loading truck is active. """
[docs]
def to_dict(self) -> dict[str, Any]:
loading_truck_id = self.loading_truck_id
etag: None | str | Unset
if isinstance(self.etag, Unset):
etag = UNSET
else:
etag = self.etag
created_by: None | str | Unset
if isinstance(self.created_by, Unset):
created_by = UNSET
else:
created_by = self.created_by
created_time: None | str | Unset
if isinstance(self.created_time, Unset):
created_time = UNSET
elif isinstance(self.created_time, datetime.datetime):
created_time = self.created_time.isoformat()
else:
created_time = self.created_time
last_modified_by: None | str | Unset
if isinstance(self.last_modified_by, Unset):
last_modified_by = UNSET
else:
last_modified_by = self.last_modified_by
last_modified_time: None | str | Unset
if isinstance(self.last_modified_time, Unset):
last_modified_time = UNSET
elif isinstance(self.last_modified_time, datetime.datetime):
last_modified_time = self.last_modified_time.isoformat()
else:
last_modified_time = self.last_modified_time
name: None | str | Unset
if isinstance(self.name, Unset):
name = UNSET
else:
name = self.name
active = self.active
field_dict: dict[str, Any] = {}
field_dict.update({})
if loading_truck_id is not UNSET:
field_dict["loadingTruckId"] = loading_truck_id
if etag is not UNSET:
field_dict["etag"] = etag
if created_by is not UNSET:
field_dict["createdBy"] = created_by
if created_time is not UNSET:
field_dict["createdTime"] = created_time
if last_modified_by is not UNSET:
field_dict["lastModifiedBy"] = last_modified_by
if last_modified_time is not UNSET:
field_dict["lastModifiedTime"] = last_modified_time
if name is not UNSET:
field_dict["name"] = name
if active is not UNSET:
field_dict["active"] = active
return field_dict
[docs]
@classmethod
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
d = dict(src_dict)
loading_truck_id = d.pop("loadingTruckId", 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_created_by(data: object) -> None | str | Unset:
if data is None:
return data
if isinstance(data, Unset):
return data
return cast(None | str | Unset, data)
created_by = _parse_created_by(d.pop("createdBy", UNSET))
def _parse_created_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()
created_time_type_0 = datetime.datetime.fromisoformat(data)
return created_time_type_0
except (TypeError, ValueError, AttributeError, KeyError):
pass
return cast(datetime.datetime | None | Unset, data)
created_time = _parse_created_time(d.pop("createdTime", UNSET))
def _parse_last_modified_by(data: object) -> None | str | Unset:
if data is None:
return data
if isinstance(data, Unset):
return data
return cast(None | str | Unset, data)
last_modified_by = _parse_last_modified_by(d.pop("lastModifiedBy", UNSET))
def _parse_last_modified_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()
last_modified_time_type_0 = datetime.datetime.fromisoformat(data)
return last_modified_time_type_0
except (TypeError, ValueError, AttributeError, KeyError):
pass
return cast(datetime.datetime | None | Unset, data)
last_modified_time = _parse_last_modified_time(d.pop("lastModifiedTime", UNSET))
def _parse_name(data: object) -> None | str | Unset:
if data is None:
return data
if isinstance(data, Unset):
return data
return cast(None | str | Unset, data)
name = _parse_name(d.pop("name", UNSET))
active = d.pop("active", UNSET)
loading_truck_model = cls(
loading_truck_id=loading_truck_id,
etag=etag,
created_by=created_by,
created_time=created_time,
last_modified_by=last_modified_by,
last_modified_time=last_modified_time,
name=name,
active=active,
)
return loading_truck_model