from dataclasses import dataclass @dataclass(frozen=True, slots=True) class ServiceUnitData: name: str @dataclass(frozen=True, slots=True) class ServiceData: name: str @dataclass(frozen=True, slots=True) class WorkTypeData: """``service_id`` None places the work type directly under its service unit.""" name: str service_id: int | None = None # --- Read models --------------------------------------------------------------------------------- @dataclass(frozen=True, slots=True) class WorkTypeNode: id: int service_unit_id: int service_id: int | None name: str is_active: bool is_selectable: bool # active and every parent active @dataclass(frozen=True, slots=True) class ServiceNode: id: int service_unit_id: int name: str is_active: bool work_types: tuple[WorkTypeNode, ...] @dataclass(frozen=True, slots=True) class ServiceUnitNode: """One service unit of the base data tree, inactive rows included.""" id: int name: str is_shared: bool is_active: bool services: tuple[ServiceNode, ...] work_types: tuple[WorkTypeNode, ...] # directly under the unit @dataclass(frozen=True, slots=True) class ServiceUnitSummary: """What other modules (jobs) see of a service unit.""" id: int name: str is_shared: bool @dataclass(frozen=True, slots=True) class WorkTypeOption: """A work type as other modules (tasks, time tracking) list and show it.""" id: int name: str service_unit_id: int service_unit_name: str service_name: str | None is_selectable: bool @property def label(self) -> str: """E.g. "Mediatuotanto / Videotuotanto / Editointi".""" parts = [self.service_unit_name, self.service_name, self.name] return " / ".join(p for p in parts if p)