from pathlib import Path
import ast

folder = Path(__file__).resolve().parent
backup = folder / "core" / "viewsbackup2.py"
print("Checking:", backup)

if not backup.exists():
    print("FAIL: viewsbackup2.py was not found.")
else:
    source = backup.read_text(encoding="utf-8")

    try:
        tree = ast.parse(source, filename=str(backup))
        print("PASS: Python syntax is valid.")

        functions = {
            node.name for node in ast.walk(tree)
            if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef))
        }

        required = {
            "home",
            "staff_login",
            "dashboard",
            "staff_logout",
            "db_status",
        }

        missing = required - functions

        if missing:
            print("FAIL: Missing functions:", ", ".join(sorted(missing)))
        else:
            print("PASS: All five required portal views exist.")

    except SyntaxError as error:
        print("FAIL: Syntax error on line", error.lineno)
        print(error.msg)