"""Verify the example and solution in a disposable copy."""

import shutil
import subprocess
import tempfile
from pathlib import Path

ROOT = Path(__file__).resolve().parent
FILES = [
    "CMakeLists.txt",
    "fixtures/orders-v1.json",
    "fixtures/orders-v2.json",
    "main.cpp",
    "order.hpp",
    "repository.hpp",
    "result.hpp",
    "solution.cpp",
    "test_support.hpp",
    "tests.cpp",
    "verify.py",
]
COMMANDS = [["python3", "verify.py"]]

with tempfile.TemporaryDirectory(prefix="appfabrik-learning-") as temporary:
    work = Path(temporary)
    for name in FILES:
        target = work / name
        target.parent.mkdir(parents=True, exist_ok=True)
        shutil.copyfile(ROOT / name, target)
    for command in COMMANDS:
        print("Running:", " ".join(command), flush=True)
        subprocess.run(command, cwd=work, check=True, timeout=900)
print("Example and solution checks completed.")
