import os
import importlib
from json import load
from typing import Dict, Any, List


def list_json_files_in_subdir(package: str) -> List[str]:
    """
    List all JSON files in the specified subdirectory package.

    Args:
        package (str): The name of the package to list JSON files from.

    Returns:
        List[str]: List of filenames ending in .json
    """
    try:
        # Dynamically load the specified package using importlib
        package_module = importlib.import_module(package)
        package_path = os.path.dirname(package_module.__file__)

        # List all files in the specified package and filter for JSON files
        json_files = [
            file for file in os.listdir(package_path) if file.endswith(".json")
        ]
        return json_files

    except Exception as e:
        raise Exception(f"Failed to list JSON files: {e}")


def prepare_json_table(path_to_table: str) -> list[Dict]:
    """
    Deserialized a json file representing a table into Python types,
    for subsequent operations

    Args:
        table (json): json file

    Returns:
        list[Dict]
    """
    reserialized_object = None
    with open(path_to_table, 'r', encoding='utf-8') as file:
        reserialized_object = load(file)

    return reserialized_object


def get_json_table(path_to_table: str) -> list[Dict]:
    """

    Args:
        path_to_table (str): _description_
    """
    print(f"path_to_table: {path_to_table}")
