#!/usr/bin/env python3
"""Verify that the project no longer exposes an internal IP/port in URLs."""
from pathlib import Path
import re
from config import PUBLIC_BASE_URL

ROOT = Path(__file__).resolve().parent
LEGACY = re.compile(r"(?:https?://)(?:14\.139\.181\.163|115\.240\.192\.141|localhost):5899")
TEXT_EXTENSIONS = {".py", ".html", ".json", ".md", ".txt", ".conf", ".service"}

errors = []
for path in ROOT.rglob("*"):
    if not path.is_file() or path.suffix.lower() not in TEXT_EXTENSIONS:
        continue
    try:
        text = path.read_text(encoding="utf-8")
    except UnicodeDecodeError:
        continue
    if LEGACY.search(text):
        errors.append(path.relative_to(ROOT))

print(f"Public base URL: {PUBLIC_BASE_URL}")
if errors:
    print("FAIL: legacy host/port found in:")
    for p in errors:
        print(f"  - {p}")
    raise SystemExit(1)

print("PASS: no legacy IP/port found in project text/data files.")
print("PASS: QR generation is configured to use the public CIBA URL.")
