from typing import Tuple
from typing import List


def read_maze_file(
    filepath: str,
) -> Tuple[List[List[int]], int, int, List[Tuple[int, int, str]], List[str]]:
    """Read a maze file and return values

    Args:
        filepath (str): path to a maze file

    Returns:
        Tuple[List[List[int]]: a maze
        int: maze width
        int: maze height
        List[Tuple[int, int, str]]: turn by turn directions
        List[str]]: texture names
    """
    with open(filepath, "r") as maze_file:
        num_textures = int(maze_file.readline())
        texture_names = [maze_file.readline() for _ in range(num_textures)]
        maze_x_dim, maze_y_dim = [int(dim) for dim in maze_file.readline().split()]
        maze = [
            [int(cell) for cell in maze_file.readline().split()]
            for _ in range(maze_y_dim)
        ]
        maze_directions = [
            (int(line.split()[0]), int(line.split()[1]), line.split()[2])
            for line in maze_file.readlines()
        ]

    return list(reversed(maze)), maze_x_dim, maze_y_dim, maze_directions, texture_names