class_name InventoryClass
extends Node

signal currency_changed(new_amount: float)
signal currency_added(amount: float, new_total: float)
signal currency_spent(amount: float, new_total: float)
signal wood_changed(new_amount: float)
signal wood_added(amount: float, new_total: float)
signal wood_spent(amount: float, new_total: float)
signal stock_changed(new_amount: float)
signal stock_added(amount: float, new_total: float)
signal stock_spent(amount: float, new_total: float)

var inventory: InventoryResource = load("res://resources/InventoryData.tres")

func get_currency() -> float:
	return inventory.currency

func add_currency(amount: float):
	inventory.currency += amount
	currency_added.emit(amount, inventory.currency)
	currency_changed.emit(inventory.currency)

func spend_currency(amount: float) -> bool:
	if inventory.currency >= amount:
		inventory.currency -= amount
		currency_spent.emit(amount, inventory.currency)
		currency_changed.emit(inventory.currency)
		return true
	return false

func get_wood() -> float:
	return inventory.wood

func add_wood(amount: float):
	inventory.wood += amount
	wood_added.emit(amount, inventory.wood)
	wood_changed.emit(inventory.wood)

func spend_wood(amount: float) -> bool:
	if inventory.wood >= amount:
		inventory.wood -= amount
		wood_spent.emit(amount, inventory.wood)
		wood_changed.emit(inventory.wood)
		return true
	return false

func get_stock() -> float:
	return inventory.stock

func add_stock(amount: float):
	# Log.pr("Adding stock: " + str(amount))
	inventory.stock += amount
	stock_added.emit(amount, inventory.stock)
	stock_changed.emit(inventory.stock)

func spend_stock(amount: float) -> bool:
	if inventory.stock >= amount:
		inventory.stock -= amount
		stock_spent.emit(amount, inventory.stock)
		stock_changed.emit(inventory.stock)
		return true
	return false
