#!/usr/bin/env python3
"""Verify the MVP frontend uses real UMG widgets instead of native paint hit boxes."""

from pathlib import Path


REPO_ROOT = Path(__file__).resolve().parents[1]
HEADER = REPO_ROOT / "Source" / "AgrarianGame" / "AgrarianMvpFrontendWidget.h"
SOURCE = REPO_ROOT / "Source" / "AgrarianGame" / "AgrarianMvpFrontendWidget.cpp"
ROADMAP = REPO_ROOT / "AGRARIAN_DEVELOPMENT_ROADMAP.md"


def require(condition: bool, message: str) -> None:
    if not condition:
        raise SystemExit(f"FAILED: {message}")


def main() -> None:
    header = HEADER.read_text(encoding="utf-8")
    source = SOURCE.read_text(encoding="utf-8")
    roadmap = ROADMAP.read_text(encoding="utf-8")

    for token in (
        "class UButton;",
        "class UTextBlock;",
        "RebuildFrontendTree",
        "HandlePrimaryActionClicked",
        "HandleBackClicked",
        "HandleSaveAndQuitClicked",
        "HandleMaleCharacterClicked",
        "HandleFemaleCharacterClicked",
    ):
        require(token in header, f"missing frontend UMG declaration: {token}")

    for token in (
        "WidgetTree->ConstructWidget",
        "UButton::StaticClass()",
        "UTextBlock::StaticClass()",
        "OnClicked.AddDynamic",
        "SetBackgroundColor",
        "DeferFrontendAction",
        "SetIsFocusable(true)",
        "SetKeyboardFocus()",
        "BackFromActiveScreen()",
        "SaveAndQuit()",
    ):
        require(token in source, f"missing frontend UMG implementation token: {token}")

    for removed_token in (
        "FSlateDrawElement",
        "NativePaint",
        "NativeOnMouseButtonDown",
        "GetPanelLayout",
        "IsPointInside",
        "DrawMainMenu",
        "DrawCharacterSelection",
        "DrawJoinServer",
        "DrawLoading",
        "DrawTextAt",
    ):
        require(removed_token not in source, f"native-painted frontend path still present: {removed_token}")
        require(removed_token not in header, f"native-painted frontend declaration still present: {removed_token}")

    require(
        "- [x] Replace the native painted MVP frontend with a proper UMG menu flow" in roadmap,
        "0.1.O UMG frontend roadmap item is not checked off",
    )

    print("OK: MVP frontend uses UMG controls with mouse, focus, hover, back, and save/quit paths.")


if __name__ == "__main__":
    main()
