class_name CraftingRecipes
extends RefCounted

static var RECIPES: Array = [
	{
		"name": "Lampe bioluminescente",
		"inputs": [{"item_id": 5, "count": 2}, {"item_id": 6, "count": 1}],
		"output": {"item_id": 100, "count": 1}
	},
	{
		"name": "Harpon",
		"inputs": [{"item_id": 3, "count": 2}, {"item_id": 7, "count": 2}],
		"output": {"item_id": 101, "count": 1}
	},
	{
		"name": "Bulle d'air",
		"inputs": [{"item_id": 6, "count": 3}, {"item_id": 8, "count": 1}],
		"output": {"item_id": 102, "count": 1}
	},
	{
		"name": "Algue cuisinee",
		"inputs": [{"item_id": 6, "count": 2}],
		"output": {"item_id": 103, "count": 2}
	},
	{
		"name": "Armure ecailles",
		"inputs": [{"item_id": 4, "count": 4}, {"item_id": 7, "count": 2}],
		"output": {"item_id": 104, "count": 1}
	},
]


static func find_available_recipes(inventory: Inventory) -> Array:
	var available: Array = []
	for i: int in range(RECIPES.size()):
		if inventory.has_items(RECIPES[i]["inputs"]):
			available.append(i)
	return available


static func craft(inventory: Inventory, recipe_index: int) -> bool:
	if recipe_index < 0 or recipe_index >= RECIPES.size():
		return false
	var recipe: Dictionary = RECIPES[recipe_index]
	if not inventory.consume_items(recipe["inputs"]):
		return false
	var leftover: int = inventory.add_item(recipe["output"]["item_id"], recipe["output"]["count"])
	if leftover > 0:
		push_warning("CraftingRecipes: craft overflow — %d items lost" % leftover)
	return true
