#!/usr/bin/env python3
"""Verify grass/forest ignition checks use fire risk, foliage fuel, and weather."""

from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]
FOLIAGE_H = ROOT / "Source" / "AgrarianGame" / "AgrarianFoliagePatch.h"
FOLIAGE_CPP = ROOT / "Source" / "AgrarianGame" / "AgrarianFoliagePatch.cpp"
FIRE_H = ROOT / "Source" / "AgrarianGame" / "AgrarianCampfire.h"
FIRE_CPP = ROOT / "Source" / "AgrarianGame" / "AgrarianCampfire.cpp"
TDD = ROOT / "Docs" / "TechnicalDesignDocument.md"
ROADMAP = ROOT / "AGRARIAN_DEVELOPMENT_ROADMAP.md"

REQUIRED = {
    FOLIAGE_H: [
        "GetFuelCountsNearLocation",
        "GetDryVegetationFuelScoreNearLocation",
        "CountInstancesNearLocation",
    ],
    FOLIAGE_CPP: [
        "AAgrarianFoliagePatch::GetFuelCountsNearLocation",
        "AAgrarianFoliagePatch::GetDryVegetationFuelScoreNearLocation",
        "AAgrarianFoliagePatch::CountInstancesNearLocation",
        "GetInstanceTransform",
        "FVector::DistSquared2D",
    ],
    FIRE_H: [
        "GrassIgnitionRiskScore",
        "ForestIgnitionRiskScore",
        "bGrassOrBrushIgnited",
        "bForestFuelIgnited",
        "VegetationIgnitionCheckRadius",
        "VegetationIgnitionFuelScoreThreshold",
        "UpdateVegetationIgnitionRisk",
        "GetVegetationFuelScoreNearFire",
        "GetVegetationIgnitionWeatherMultiplier",
    ],
    FIRE_CPP: [
        "#include \"AgrarianFoliagePatch.h\"",
        "DOREPLIFETIME(AAgrarianCampfire, GrassIgnitionRiskScore)",
        "DOREPLIFETIME(AAgrarianCampfire, ForestIgnitionRiskScore)",
        "UpdateVegetationIgnitionRisk(DeltaSeconds);",
        "UGameplayStatics::GetAllActorsOfClass(this, AAgrarianFoliagePatch::StaticClass()",
        "GameState->ActiveWeatherInputs.WindSpeedKmh",
        "EAgrarianWeatherType::Rain",
        "EAgrarianWeatherType::Storm",
        "EAgrarianWeatherType::ColdWind",
        "LitDurationSeconds",
        "GetFireRiskRatio()",
        "bGrassOrBrushIgnited = GrassIgnitionRiskScore >= 100.0f",
        "bForestFuelIgnited = ForestIgnitionRiskScore >= 100.0f",
    ],
    TDD: [
        "Grass and forest ignition checks consume that risk score",
        "`AAgrarianFoliagePatch`",
        "wind speed",
        "burn\nduration",
    ],
    ROADMAP: [
        "[x] Add grass and forest ignition checks",
    ],
}


def main() -> None:
    missing = []
    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: vegetation ignition checks are wired to fire risk, foliage, and weather.")


if __name__ == "__main__":
    main()
