from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]
FILES = {
    "AgrarianMvpFrontendWidget.h": ROOT / "Source" / "AgrarianGame" / "AgrarianMvpFrontendWidget.h",
    "AgrarianMvpFrontendWidget.cpp": ROOT / "Source" / "AgrarianGame" / "AgrarianMvpFrontendWidget.cpp",
    "AgrarianGamePlayerController.h": ROOT / "Source" / "AgrarianGame" / "AgrarianGamePlayerController.h",
    "AgrarianGamePlayerController.cpp": ROOT / "Source" / "AgrarianGame" / "AgrarianGamePlayerController.cpp",
}

EXPECTED = {
    "AgrarianMvpFrontendWidget.h": [
        "ConfirmActiveScreen",
        "BackFromActiveScreen",
        "SaveAndQuit",
    ],
    "AgrarianMvpFrontendWidget.cpp": [
        "UButton::StaticClass()",
        "HandleMaleCharacterClicked",
        "HandleFemaleCharacterClicked",
        "OnClicked.AddDynamic",
        "Save & Quit",
        "Saving World",
        "ConsoleCommand(TEXT(\"AgrarianSaveWorld\"))",
        "ConsoleCommand(TEXT(\"quit\"))",
        "PlayerController->SetIgnoreMoveInput(false)",
        "PlayerController->SetIgnoreLookInput(false)",
    ],
    "AgrarianGamePlayerController.h": [
        "ShowMvpPauseMenu",
        "HandleMvpEscapeInput",
    ],
    "AgrarianGamePlayerController.cpp": [
        "SetIgnoreMoveInput(true)",
        "SetIgnoreLookInput(true)",
        "FInputModeUIOnly",
        "InputComponent->BindKey(EKeys::Enter",
        "InputComponent->BindKey(EKeys::SpaceBar",
        "InputComponent->BindKey(EKeys::Escape",
        "MvpFrontendWidget->IsInViewport()",
        "ShowMvpPauseMenu();",
    ],
}

FORBIDDEN = {
    "AgrarianGamePlayerController.cpp": [
        "BindKey(EKeys::LeftMouseButton",
    ],
}


def main():
    failures = []
    for label, path in FILES.items():
        text = path.read_text(encoding="utf-8")
        for snippet in EXPECTED[label]:
            if snippet not in text:
                failures.append(f"{label} missing {snippet!r}")

        for snippet in FORBIDDEN.get(label, []):
            if snippet in text:
                failures.append(f"{label} should not contain {snippet!r}")

    if failures:
        raise RuntimeError("MVP menu input and quit flow verification failed: " + "; ".join(failures))

    print("Agrarian MVP menu input and quit flow verification complete.")


if __name__ == "__main__":
    main()
