import unreal


ITEM_FOLDER = "/Game/Agrarian/DataAssets/Items"

EXPECTED_ITEMS = {
    "DA_Item_Wood": ("wood", unreal.AgrarianItemType.RESOURCE),
    "DA_Item_Stone": ("stone", unreal.AgrarianItemType.RESOURCE),
    "DA_Item_Fiber": ("fiber", unreal.AgrarianItemType.RESOURCE),
    "DA_Item_Food": ("food", unreal.AgrarianItemType.FOOD),
    "DA_Item_Meat": ("meat", unreal.AgrarianItemType.FOOD),
    "DA_Item_Hide": ("hide", unreal.AgrarianItemType.RESOURCE),
    "DA_Item_PrimitiveFrame": ("primitive_frame", unreal.AgrarianItemType.STRUCTURE),
    "DA_Item_PrimitiveWallPanel": ("primitive_wall_panel", unreal.AgrarianItemType.STRUCTURE),
    "DA_Item_PrimitiveRoofPanel": ("primitive_roof_panel", unreal.AgrarianItemType.STRUCTURE),
    "DA_Item_Campfire": ("campfire", unreal.AgrarianItemType.STRUCTURE),
    "DA_Item_PrimitiveShelter": ("primitive_shelter", unreal.AgrarianItemType.STRUCTURE),
    "DA_Item_SimpleContainer": ("simple_container", unreal.AgrarianItemType.STRUCTURE),
    "DA_Item_BasicTool": ("basic_tool", unreal.AgrarianItemType.TOOL),
    "DA_Item_Bandage": ("bandage", unreal.AgrarianItemType.MEDICINE),
}


def main():
    missing = []

    for asset_name, (expected_item_id, expected_type) in EXPECTED_ITEMS.items():
        path = f"{ITEM_FOLDER}/{asset_name}"
        asset = unreal.EditorAssetLibrary.load_asset(path)
        if not asset:
            missing.append(f"{path} missing")
            continue

        definition = asset.get_editor_property("definition")
        item_id = str(definition.get_editor_property("item_id"))
        display_name = str(definition.get_editor_property("display_name"))
        description = str(definition.get_editor_property("description"))
        item_type = definition.get_editor_property("item_type")
        unit_weight = definition.get_editor_property("unit_weight")
        max_stack_size = definition.get_editor_property("max_stack_size")

        if item_id != expected_item_id:
            missing.append(f"{path} item_id expected {expected_item_id}, got {item_id}")
        if item_type != expected_type:
            missing.append(f"{path} type expected {expected_type}, got {item_type}")
        if not display_name:
            missing.append(f"{path} display_name empty")
        if not description:
            missing.append(f"{path} description empty")
        if unit_weight <= 0.0:
            missing.append(f"{path} unit_weight must be positive")
        if max_stack_size < 1:
            missing.append(f"{path} max_stack_size must be positive")

    if missing:
        raise RuntimeError("Item definition verification failed: " + "; ".join(missing))

    unreal.log("Agrarian item definition verification complete.")


main()
