from src.solver.search_stats import SearchStats

class MazeSolver:
    def __init__(self, maze, strategy):
        self.maze = maze
        self.strategy = strategy

    def solve(self):
        import time
        t0 = time.perf_counter()

        # если выхода нет — сразу возвращаем пустой результат
        if self.maze.exit is None:
            t1 = time.perf_counter()
            return SearchStats(
                time_ms=(t1 - t0) * 1000,
                visited=0,
                path_len=0
            )

        path, visited = self.strategy.find_path(
            self.maze,
            self.maze.start,
            self.maze.exit
        )

        t1 = time.perf_counter()

        return SearchStats(
            time_ms=(t1 - t0) * 1000,
            visited=len(visited),
            path_len=len(path) if path else 0
        )
