extends GdUnitTestSuite

## NEO-73: nearest in-range resource node picker for gather interact.

const Picker := preload("res://scripts/prototype_interactable_picker.gd")


static func _descriptor(id: String, kind: String, x: float, z: float, radius: float) -> Dictionary:
	return {
		"interactableId": id,
		"kind": kind,
		"anchor": {"x": x, "y": 0.5, "z": z},
		"interactionRadius": radius,
	}


func test_nearest_resource_node_picks_closest_in_range() -> void:
	# Arrange
	var descriptors: Array = [
		_descriptor("prototype_terminal", "terminal", 0.0, 0.0, 3.0),
		_descriptor("prototype_resource_node_alpha", "resource_node", 12.0, -6.0, 3.0),
		_descriptor("prototype_subsurface_vein_beta", "resource_node", 18.0, -6.0, 3.0),
	]
	var world := Vector3(17.0, 0.9, -6.0)
	# Act
	var picked: String = Picker.nearest_resource_node_id(descriptors, world)
	# Assert
	assert_that(picked).is_equal("prototype_subsurface_vein_beta")


func test_nearest_resource_node_falls_back_to_alpha_when_out_of_range() -> void:
	# Arrange
	var descriptors: Array = [
		_descriptor("prototype_resource_node_alpha", "resource_node", 12.0, -6.0, 3.0),
	]
	var world := Vector3(-5.0, 0.9, -5.0)
	# Act
	var picked: String = Picker.nearest_resource_node_id(descriptors, world)
	# Assert
	assert_that(picked).is_equal("prototype_resource_node_alpha")


func test_is_resource_node_id_uses_known_ids_when_catalog_empty() -> void:
	# Arrange
	# Act
	var is_node: bool = Picker.is_resource_node_id([], "prototype_bio_mat_gamma")
	# Assert
	assert_that(is_node).is_true()
