extends StateMachine

enum States {IDLE, RANDOMMOVEMENT, FEEDING, FLEEING, HUNTING}

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	super()
	await owner.ready


func transition_to_next_state(target: int, data: Dictionary = {}) -> void:
	match target:
		States.IDLE: _transition_to_next_state("Idle", data)
		States.RANDOMMOVEMENT: _transition_to_next_state("RandomMovement", data)
		States.FEEDING: _transition_to_next_state("Feeding", data)
		States.FLEEING: _transition_to_next_state("Fleeing", data)
		States.HUNTING: _transition_to_next_state("Hunting", data)
		_: push_error("Trying to transition to unknown state {target}")
		
func map(state: Node) -> States:
	match state.name:
		"Idle": return States.IDLE
		"RandomMovement": return States.RANDOMMOVEMENT
		"Feeding": return States.FEEDING
		"Fleeing": return States.FLEEING
		"Hunting": return States.HUNTING
		_: push_error("Unknown state {state.name}")
	return map(self.initial_state)
