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 ..types import UNSET, Unset
if TYPE_CHECKING:
from ..models.backfilling_entry_actual import BackfillingEntryActual
from ..models.backfilling_entry_plan import BackfillingEntryPlan
T = TypeVar("T", bound="BackfillingEntryModel")
[docs]
@_attrs_define
class BackfillingEntryModel:
"""Details of a backfilling activity on a hole."""
hole_id: int
""" The ID of the hole this backfilling activity relates to. Cannot be edited. """
plan: BackfillingEntryPlan
""" Instructions on how a backfilling activity should be performed. """
backfilling_entry_id: int | None | Unset = UNSET
""" The unique identifier of this backfilling entry. Ignored when creating. Cannot be edited. """
etag: None | str | Unset = UNSET
""" The backfilling entry's current ETag. Required when editing in bulk. """
created_by: None | str | Unset = UNSET
""" Username of the person who created this backfilling entry. Ignored when creating and editing. """
last_modified_by: None | str | Unset = UNSET
""" Username of the person who last updated this backfilling entry. Ignored when creating and editing. """
last_modified_time: datetime.datetime | None | Unset = UNSET
""" When this backfilling entry was last updated (UTC). Ignored when creating and editing. """
created_time: datetime.datetime | None | Unset = UNSET
""" When this backfilling entry was created (UTC). Ignored when editing. Defaults to current time when not
supplied. """
cancelled_time: datetime.datetime | None | Unset = UNSET
""" When this activity was cancelled (UTC). Can be null to indicate not cancelled. 'actual' must be null when
'cancelledTime' is not null. """
actual: BackfillingEntryActual | None | Unset = UNSET
""" Measurements recorded from the backfilling activity. 'cancelledTime' must be null when 'actual' is not null.
"""
[docs]
def to_dict(self) -> dict[str, Any]:
from ..models.backfilling_entry_actual import BackfillingEntryActual # noqa: PLC0415
hole_id = self.hole_id
plan = self.plan.to_dict()
backfilling_entry_id: int | None | Unset
if isinstance(self.backfilling_entry_id, Unset):
backfilling_entry_id = UNSET
else:
backfilling_entry_id = self.backfilling_entry_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
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
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
cancelled_time: None | str | Unset
if isinstance(self.cancelled_time, Unset):
cancelled_time = UNSET
elif isinstance(self.cancelled_time, datetime.datetime):
cancelled_time = self.cancelled_time.isoformat()
else:
cancelled_time = self.cancelled_time
actual: dict[str, Any] | None | Unset
if isinstance(self.actual, Unset):
actual = UNSET
elif isinstance(self.actual, BackfillingEntryActual):
actual = self.actual.to_dict()
else:
actual = self.actual
field_dict: dict[str, Any] = {}
field_dict.update(
{
"holeId": hole_id,
"plan": plan,
}
)
if backfilling_entry_id is not UNSET:
field_dict["backfillingEntryId"] = backfilling_entry_id
if etag is not UNSET:
field_dict["etag"] = etag
if created_by is not UNSET:
field_dict["createdBy"] = created_by
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 created_time is not UNSET:
field_dict["createdTime"] = created_time
if cancelled_time is not UNSET:
field_dict["cancelledTime"] = cancelled_time
if actual is not UNSET:
field_dict["actual"] = actual
return field_dict
[docs]
@classmethod
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
from ..models.backfilling_entry_actual import BackfillingEntryActual # noqa: PLC0415
from ..models.backfilling_entry_plan import BackfillingEntryPlan # noqa: PLC0415
d = dict(src_dict)
hole_id = d.pop("holeId")
plan = BackfillingEntryPlan.from_dict(d.pop("plan"))
def _parse_backfilling_entry_id(data: object) -> int | None | Unset:
if data is None:
return data
if isinstance(data, Unset):
return data
return cast(int | None | Unset, data)
backfilling_entry_id = _parse_backfilling_entry_id(d.pop("backfillingEntryId", 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_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_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_cancelled_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()
cancelled_time_type_0 = datetime.datetime.fromisoformat(data)
return cancelled_time_type_0
except (TypeError, ValueError, AttributeError, KeyError):
pass
return cast(datetime.datetime | None | Unset, data)
cancelled_time = _parse_cancelled_time(d.pop("cancelledTime", UNSET))
def _parse_actual(data: object) -> BackfillingEntryActual | None | Unset:
if data is None:
return data
if isinstance(data, Unset):
return data
try:
if not isinstance(data, dict):
raise TypeError()
actual_type_0 = BackfillingEntryActual.from_dict(data)
return actual_type_0
except (TypeError, ValueError, AttributeError, KeyError):
pass
return cast(BackfillingEntryActual | None | Unset, data)
actual = _parse_actual(d.pop("actual", UNSET))
backfilling_entry_model = cls(
hole_id=hole_id,
plan=plan,
backfilling_entry_id=backfilling_entry_id,
etag=etag,
created_by=created_by,
last_modified_by=last_modified_by,
last_modified_time=last_modified_time,
created_time=created_time,
cancelled_time=cancelled_time,
actual=actual,
)
return backfilling_entry_model