Source code for maptekblastlogic.models.crew_model

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="CrewModel")


[docs] @_attrs_define class CrewModel: """A crew and their responsibilities.""" crew_id: int | Unset = UNSET """ The unique identifier of this crew. """ etag: None | str | Unset = UNSET """ The crew's current ETag. Ignored when creating and editing. """ created_by: None | str | Unset = UNSET """ Username of the person who created this crew. Ignored when creating and editing. """ created_time: datetime.datetime | None | Unset = UNSET """ When this crew was last updated (UTC). Ignored when creating and editing. """ last_modified_by: None | str | Unset = UNSET """ Username of the person who last updated this crew. Ignored when creating and editing. """ last_modified_time: datetime.datetime | None | Unset = UNSET """ When this crew was last updated (UTC). Ignored when creating and editing. """ name: None | str | Unset = UNSET """ The name of this crew. """ is_active: bool | Unset = UNSET """ Whether this crew is active. """ is_dipping_crew: bool | Unset = UNSET """ Whether this crew can perform dipping duties. """ is_backfilling: bool | Unset = UNSET """ Whether this crew can perform backfilling duties. """ is_charging_crew: bool | Unset = UNSET """ Whether this crew can perform charging duties. """
[docs] def to_dict(self) -> dict[str, Any]: crew_id = self.crew_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 is_active = self.is_active is_dipping_crew = self.is_dipping_crew is_backfilling = self.is_backfilling is_charging_crew = self.is_charging_crew field_dict: dict[str, Any] = {} field_dict.update({}) if crew_id is not UNSET: field_dict["crewId"] = crew_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 is_active is not UNSET: field_dict["isActive"] = is_active if is_dipping_crew is not UNSET: field_dict["isDippingCrew"] = is_dipping_crew if is_backfilling is not UNSET: field_dict["isBackfilling"] = is_backfilling if is_charging_crew is not UNSET: field_dict["isChargingCrew"] = is_charging_crew return field_dict
[docs] @classmethod def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: d = dict(src_dict) crew_id = d.pop("crewId", 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)) is_active = d.pop("isActive", UNSET) is_dipping_crew = d.pop("isDippingCrew", UNSET) is_backfilling = d.pop("isBackfilling", UNSET) is_charging_crew = d.pop("isChargingCrew", UNSET) crew_model = cls( crew_id=crew_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, is_active=is_active, is_dipping_crew=is_dipping_crew, is_backfilling=is_backfilling, is_charging_crew=is_charging_crew, ) return crew_model