class_name BaseState
extends Node

@export var state_machine: PlayerStateMachine

var _subscribed_events: Array[String] = []
var _subscribed_events_callables: Array[Callable] = []

func GetStateEnum() -> PlayerStateMachine.States:
	push_error("Unimplemented Method: BaseState.GetStateEnum")
	return PlayerStateMachine.States.IDLE


func GetAnimationBaseName() -> String:
	var state: String = PlayerStateMachine.States.keys()[GetStateEnum()]
	return state.to_lower()


func Enter(_extra_parameters: Dictionary) -> void:
	pass


func Exit() -> void:
	pass


func Update(_delta: float) -> void:
	pass


func IsActive() -> bool:
	return state_machine.GetCurrentStateEnum() == GetStateEnum()


func IsStateActionable() -> bool:
	return true


func SubscribeToEvent(event_name: String, callback: Callable) -> void:
	if _subscribed_events.has(event_name):
		return
	_subscribed_events.append(event_name)
	_subscribed_events_callables.append(callback)


# State Machine Visibility Only
func _StateMachine_OnEventSent(event_name: String, parameters: Variant) -> void:
	var idx := _subscribed_events.find(event_name)
	if idx == -1:
		push_error("THIS SHOULD NEVER HAPPEN LOL")
	
	var callable := _subscribed_events_callables[idx]
	if callable.get_argument_count() == 0:
		callable.call()
	else:
		callable.call(parameters)
