from Code.Communication.Direction import Direction


class EdgeSync:

	def __init__(self, current_edges: dict, counter: int):
		self.old_edges = {}
		self.current_edges = current_edges
		self.counter = counter
		self.counter_old = counter - 1

	def get_edge(self, edg_pos: Direction, counter: int) -> list:
		while counter == self.counter + 1:
			pass

		if counter == self.counter:
			return self.current_edges[edg_pos]
		elif counter == self.counter_old:
			return self.old_edges[edg_pos]
		else:
			raise ValueError(f"Requested edge for counter {counter}, but having counter {self.counter} ")


	def update_edges(self, new_edges, counter: int):
		self.counter_old = self.counter
		self.counter = counter
		self.old_edges = self.current_edges
		self.current_edges = new_edges
