extends State

const PATROL_STATE_ID: StringName = &"patrol"

@export var wait_time: float = 3.0

var runtime_timer: Timer

func enter() -> void:
	runtime_timer = Timer.new()
	runtime_timer.name = "IdleTimer"
	add_child(runtime_timer)
	runtime_timer.one_shot = true
	runtime_timer.timeout.connect(_on_timer_timeout)
	runtime_timer.start(wait_time)

func exit() -> void:
	if runtime_timer:
		if runtime_timer.is_connected("timeout", _on_timer_timeout):
			runtime_timer.timeout.disconnect(_on_timer_timeout)
		
		runtime_timer.queue_free()
		runtime_timer = null

func _on_timer_timeout() -> void:
	transitioned.emit(self, PATROL_STATE_ID)
