class_name EconomyManagerClass
extends Node

var cash: float = 100.0
var total_earned: float = 0.0
var total_spent: float = 0.0

signal cash_changed(new_amount: float, delta: float)
signal transaction_recorded(type: String, amount: float, description: String)
signal insufficient_funds(required: float, available: float)

func _ready() -> void:
	pass

func add_cash(amount: float, description: String = "") -> void:
	cash += amount
	total_earned += amount
	cash_changed.emit(cash, amount)

func spend_cash(amount: float, description: String = "") -> bool:
	if cash < amount:
		insufficient_funds.emit(amount, cash)
		return false
	cash -= amount
	total_spent += amount
	cash_changed.emit(cash, -amount)
	return true

func can_afford(amount: float) -> bool:
	return cash >= amount

func get_profit() -> float:
	return total_earned - total_spent

func serialize() -> Dictionary:
	return {
		"cash": cash,
		"total_earned": total_earned,
		"total_spent": total_spent,
	}

func deserialize(data: Dictionary) -> void:
	cash = data.get("cash", 100.0)
	total_earned = data.get("total_earned", 0.0)
	total_spent = data.get("total_spent", 0.0)
