from pathlib import Path
import json


def load_report(project_root, filename):
    """
    Load a discovery report.

    Returns:
        dict  -> report contents
        None  -> report not found
    """

    report = (
        Path(project_root)
        / "reports"
        / "discovery"
        / filename
    )

    if not report.exists():
        return None

    with open(report, "r", encoding="utf-8") as f:
        return json.load(f)


def load_all_reports(project_root):
    """
    Load every discovery report.

    Returns a dictionary containing all available reports.
    """

    return {

        "project":
            load_report(
                project_root,
                "project_inventory.json"
            ),

        "gateway":
            load_report(
                project_root,
                "gateway_inventory.json"
            ),

        "endpoints":
            load_report(
                project_root,
                "endpoint_inventory.json"
            )

    }

if __name__ == "__main__":

    PROJECT = r"D:\xampp\htdocs\manyfest\ExplorerAssistGPT"

    reports = load_all_reports(PROJECT)

    print()
    print("Discovery Reports")
    print("-----------------")

    for name, report in reports.items():

        if report is None:
            print(f"{name:<12} : NOT FOUND")
        else:
            print(f"{name:<12} : LOADED")

    print()