"""Build guard: refuse to build a customer app with an unconfigured
license server. Called by build.bat. Exit code 1 = not ready."""
import base64
import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
from metafixer import license_config as c  # noqa: E402

problems = []
if "YOUR-DOMAIN" in c.LICENSE_API_URL or not c.LICENSE_API_URL.startswith("https://"):
    problems.append("LICENSE_API_URL must be your real https:// address of api.php")
if "YOUR-DOMAIN" in c.BUY_URL:
    problems.append("BUY_URL is still the placeholder")
try:
    if len(base64.b64decode(c.PUBLIC_KEY_B64)) != 32:
        problems.append("PUBLIC_KEY_B64 is not a 32-byte Ed25519 key")
except Exception:
    problems.append("PUBLIC_KEY_B64 is not valid base64")
if problems:
    print("\nLICENSE SETTINGS NOT READY - edit metafixer\\license_config.py:")
    for p in problems:
        print("  -", p)
    sys.exit(1)
print("License settings OK:", c.LICENSE_API_URL)
