#!/usr/bin/env python3
"""Verify the MVP server launch QA gate is documented and scripted."""

from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]
ROADMAP = ROOT / "AGRARIAN_DEVELOPMENT_ROADMAP.md"
QA_DOC = ROOT / "Docs" / "QA" / "MvpQaGates.md"
RUNBOOK = ROOT / "Docs" / "Ops" / "DedicatedServerBuildRunbook.md"
DEDICATED_BAT = ROOT / "Scripts" / "BuildLinuxDedicatedServer-Windows.bat"
FALLBACK_BAT = ROOT / "Scripts" / "PackageLinuxGameServerFallback-Windows.bat"

REQUIRED = {
    QA_DOC: [
        "## Server Launch",
        "Scripts/BuildLinuxDedicatedServer-Windows.bat",
        "Scripts/PackageLinuxGameServerFallback-Windows.bat",
        "/opt/agrarian/server/AgrarianGameServer.sh",
        "agrarian-game-server.service",
        "0.0.0.0:7777/udp",
        "Ground Zero map browse started",
    ],
    RUNBOOK: [
        "Scripts\\BuildLinuxDedicatedServer-Windows.bat",
        "Scripts\\PackageLinuxGameServerFallback-Windows.bat",
        "Deploy the fallback package to `/opt/agrarian/server`",
        "-server -port=7777 -NullRHI -nosound",
    ],
    DEDICATED_BAT: [
        "AgrarianGameServer Linux Development",
        "LINUX_MULTIARCH_ROOT",
        "Builds\\LinuxServerDevelopment",
    ],
    FALLBACK_BAT: [
        "Builds\\LinuxGameDevelopment",
        "-platform=Linux",
        "BuildCookRun",
    ],
    ROADMAP: [
        "[x] Can launch server.",
    ],
}


def main() -> None:
    missing: list[str] = []
    for path, snippets in REQUIRED.items():
        text = path.read_text(encoding="utf-8")
        for snippet in snippets:
            if snippet not in text:
                missing.append(f"{path.relative_to(ROOT)} missing {snippet!r}")
    if missing:
        raise SystemExit("FAILED: " + "; ".join(missing))
    print("OK: server launch QA gate is documented and tied to build scripts.")


if __name__ == "__main__":
    main()
