#!/usr/bin/env python3
"""Validate MVP latency testing plan and helper script."""

from pathlib import Path
import sys

ROOT = Path(__file__).resolve().parents[1]


def read(relative_path: str) -> str:
    path = ROOT / relative_path
    if not path.exists():
        raise AssertionError(f"Missing required file: {relative_path}")
    return path.read_text(encoding="utf-8")


def require(content: str, needle: str, context: str) -> None:
    if needle not in content:
        raise AssertionError(f"Missing {needle!r} in {context}")


def main() -> int:
    errors: list[str] = []
    checks = {
        "Docs/Ops/MultiplayerLatencyTestPlan.md": [
            "Clean LAN",
            "Mild WAN",
            "Rough WAN",
            "Net PktLag=80",
            "Net PktLag=160",
            "Net PktLoss=3",
            "AgrarianServerTravel GroundZero",
            "play.agrariangame.com:7777",
        ],
        "Scripts/LatencyTestProfiles-Windows.bat": [
            "Net PktLag=0",
            "Net PktLagVariance=20",
            "Net PktLoss=1",
            "Net PktLagVariance=40",
            "Net PktLoss=3",
        ],
        "Docs/MultiplayerNetworkingDesign.md": [
            "mild WAN profile",
            "rough WAN profile",
            "Docs/Ops/MultiplayerLatencyTestPlan.md",
            "Unreal packet simulation",
        ],
        "AGRARIAN_DEVELOPMENT_ROADMAP.md": [
            "[x] Add basic latency testing.",
            "clean LAN",
            "rough WAN",
        ],
    }

    for relative_path, needles in checks.items():
        try:
            content = read(relative_path)
            for needle in needles:
                require(content, needle, relative_path)
        except AssertionError as exc:
            errors.append(str(exc))

    if errors:
        for error in errors:
            print(f"ERROR: {error}", file=sys.stderr)
        return 1

    print("PASS: MVP latency testing plan and helper script are present.")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())
