"""Entity models for stores, destinations, tunnels, and trucks.""" from dataclasses import dataclass from typing import Tuple @dataclass class Store: """Represents a storage location / starting point for trucks.""" id: int position: Tuple[int, int] def to_dict(self) -> dict: return { "id": self.id, "position": {"x": self.position[0], "y": self.position[1]}, } @dataclass class Destination: """Represents a customer destination for package delivery.""" id: int position: Tuple[int, int] def to_dict(self) -> dict: return { "id": self.id, "position": {"x": self.position[0], "y": self.position[1]}, } @dataclass class Tunnel: """Represents an underground tunnel connecting two points.""" entrance1: Tuple[int, int] entrance2: Tuple[int, int] @property def cost(self) -> int: """Tunnel cost is Manhattan distance between entrances.""" return abs(self.entrance1[0] - self.entrance2[0]) + abs( self.entrance1[1] - self.entrance2[1] ) def get_other_entrance(self, entrance: Tuple[int, int]) -> Tuple[int, int]: """Get the other entrance of the tunnel.""" if entrance == self.entrance1: return self.entrance2 elif entrance == self.entrance2: return self.entrance1 raise ValueError(f"Position {entrance} is not an entrance of this tunnel") def has_entrance_at(self, pos: Tuple[int, int]) -> bool: """Check if tunnel has an entrance at given position.""" return pos == self.entrance1 or pos == self.entrance2 def to_dict(self) -> dict: return { "entrance1": {"x": self.entrance1[0], "y": self.entrance1[1]}, "entrance2": {"x": self.entrance2[0], "y": self.entrance2[1]}, "cost": self.cost, }