# Path: siebenapp/domain.py
# class Graph:
#     """Base interface definition"""
# 
#     NO_VALUE = "no value"
# 
#     def __init__(self, goaltree=None):
#         self.goaltree: Graph = goaltree
# 
#     def __getattr__(self, item):
#         """When method is not found, ask nested goaltree for it"""
#         if self.goaltree != self:
#             return getattr(self.goaltree, item)
#         return None
# 
#     def accept(self, command: Command) -> None:
#         """React on the given command"""
#         method_name = "accept_" + command.__class__.__name__
#         if method := getattr(self, method_name):
#             method(command)
#         elif parent := self.goaltree:
#             parent.accept(command)
#         else:
#             raise NotImplementedError(f"Cannot find method {method_name}")
# 
#     def accept_all(self, *commands: Command) -> None:
#         """React on the command chain"""
#         for command in commands:
#             self.accept(command)
# 
#     def settings(self, key: str) -> Any:
#         """Returns given inner value by the key"""
#         if self.goaltree is not None:
#             return self.goaltree.settings(key)
#         return Graph.NO_VALUE
# 
#     def reconfigure_from(self, origin: "Graph") -> None:
#         """Synchronize *non-persistent* settings from the given origin"""
#         if self.goaltree:
#             self.goaltree.reconfigure_from(origin)
# 
#     def selections(self) -> Set[int]:
#         """Return ids of special 'selection' goals"""
#         if self.goaltree:
#             return self.goaltree.selections()
#         raise NotImplementedError
# 
#     def events(self) -> deque:
#         """Returns queue of applied actions.
#         Note: this queue is modifiable -- you may push new events into it. But this
#         behavior may be changed in future."""
#         if self.goaltree is not None:
#             return self.goaltree.events()
#         raise NotImplementedError
# 
#     def q(self, keys: str = "name") -> Dict[int, Any]:
#         """Run search query against content"""
#         raise NotImplementedError
# 
#     def error(self, message: str) -> None:
#         """Show error message"""
#         if self.goaltree is not None:
#             self.goaltree.error(message)
# 
#     def verify(self) -> bool:
#         """Check all inner data for correctness"""
#         if self.goaltree is not None:
#             return self.goaltree.verify()
#         return False
# 
# class Command:
#     pass
# 
# def with_key(key):
#     """Wraps around Graph.q, adding given key to the request"""
# 
#     def inner(q):
#         @wraps(q)
#         def wrapper(self, keys="name"):
#             if no_key := key not in keys:
#                 keys = ",".join([keys, key])
#             result = q(self, keys)
#             if no_key:
#                 for v in result.values():
#                     v.pop(key, None)
#             return result
# 
#         return wrapper
# 
#     return inner
# 
# class EdgeType(IntEnum):
#     BLOCKER = 1
#     PARENT = 2


from dataclasses import dataclass
from typing import Dict, Any, Tuple, List
from siebenapp.domain import Graph, Command, with_key, EdgeType

class ProgressView(Graph):
    def __init__(self, goaltree: Graph):
        super().__init__(goaltree)
        self.show_progress = False

    def accept_ToggleProgress(self, command: ToggleProgress) -> None:
        self.show_progress = not self.show_progress

    def settings(self, key: str) -> Any:
        if key == "filter_progress":
            return self.show_progress
        return self.goaltree.settings(key)

    def reconfigure_from(self, origin: "Graph") -> None:
        super().reconfigure_from(origin)
        self.show_progress = origin.settings("filter_progress")

    @with_key("name")
    @with_key("open")
    @with_key("edge")
    def q(self, keys: str = "name") -> Dict[int, Any]:
        if not self.show_progress:
            return self.goaltree.q(keys)
        progress_cache: Dict[int, Tuple[int, int]] = {}
        result = self.goaltree.q(keys)
        queue: List[int] = list(result.keys())
        while queue:
            goal_id = queue.pop(0)
            children = [

# Path: siebenapp/domain.py
# class Graph:
#     """Base interface definition"""
# 
#     NO_VALUE = "no value"
# 
#     def __init__(self, goaltree=None):
#         self.goaltree: Graph = goaltree
# 
#     def __getattr__(self, item):
#         """When method is not found, ask nested goaltree for it"""
#         if self.goaltree != self:
#             return getattr(self.goaltree, item)
#         return None
# 
#     def accept(self, command: Command) -> None:
#         """React on the given command"""
#         method_name = "accept_" + command.__class__.__name__
#         if method := getattr(self, method_name):
#             method(command)
#         elif parent := self.goaltree:
#             parent.accept(command)
#         else:
#             raise NotImplementedError(f"Cannot find method {method_name}")
# 
#     def accept_all(self, *commands: Command) -> None:
#         """React on the command chain"""
#         for command in commands:
#             self.accept(command)
# 
#     def settings(self, key: str) -> Any:
#         """Returns given inner value by the key"""
#         if self.goaltree is not None:
#             return self.goaltree.settings(key)
#         return Graph.NO_VALUE
# 
#     def reconfigure_from(self, origin: "Graph") -> None:
#         """Synchronize *non-persistent* settings from the given origin"""
#         if self.goaltree:
#             self.goaltree.reconfigure_from(origin)
# 
#     def selections(self) -> Set[int]:
#         """Return ids of special 'selection' goals"""
#         if self.goaltree:
#             return self.goaltree.selections()
#         raise NotImplementedError
# 
#     def events(self) -> deque:
#         """Returns queue of applied actions.
#         Note: this queue is modifiable -- you may push new events into it. But this
#         behavior may be changed in future."""
#         if self.goaltree is not None:
#             return self.goaltree.events()
#         raise NotImplementedError
# 
#     def q(self, keys: str = "name") -> Dict[int, Any]:
#         """Run search query against content"""
#         raise NotImplementedError
# 
#     def error(self, message: str) -> None:
#         """Show error message"""
#         if self.goaltree is not None:
#             self.goaltree.error(message)
# 
#     def verify(self) -> bool:
#         """Check all inner data for correctness"""
#         if self.goaltree is not None:
#             return self.goaltree.verify()
#         return False
# 
# class Command:
#     pass
# 
# def with_key(key):
#     """Wraps around Graph.q, adding given key to the request"""
# 
#     def inner(q):
#         @wraps(q)
#         def wrapper(self, keys="name"):
#             if no_key := key not in keys:
#                 keys = ",".join([keys, key])
#             result = q(self, keys)
#             if no_key:
#                 for v in result.values():
#                     v.pop(key, None)
#             return result
# 
#         return wrapper
# 
#     return inner
# 
# class EdgeType(IntEnum):
#     BLOCKER = 1
#     PARENT = 2


# Path: siebenapp/progress_view.py
from dataclasses import dataclass
from typing import Dict, Any, Tuple, List
from siebenapp.domain import Graph, Command, with_key, EdgeType


class ProgressView(Graph):
    def __init__(self, goaltree: Graph):
        super().__init__(goaltree)
        self.show_progress = False

    def accept_ToggleProgress(self, command: ToggleProgress) -> None:
        self.show_progress = not self.show_progress

    def settings(self, key: str) -> Any:
        if key == "filter_progress":
            return self.show_progress
        return self.goaltree.settings(key)

    def reconfigure_from(self, origin: "Graph") -> None:
        super().reconfigure_from(origin)
        self.show_progress = origin.settings("filter_progress")

    @with_key("name")
    @with_key("open")
    @with_key("edge")
    def q(self, keys: str = "name") -> Dict[int, Any]:
        if not self.show_progress:
            return self.goaltree.q(keys)
        progress_cache: Dict[int, Tuple[int, int]] = {}
        result = self.goaltree.q(keys)
        queue: List[int] = list(result.keys())
        while queue:
            goal_id = queue.pop(0)
            children = [

                x[0] for x in result[goal_id]["edge"] if x[1] == EdgeType.PARENT