## Tests for ChestItemData resource and RoomChestConfig static config.
extends GutTest


func test_chest_item_data_default_item_type_is_holdable() -> void:
	var d: ChestItemData = ChestItemData.new()
	assert_eq(d.item_type, ChestItemData.ItemType.HOLDABLE)


func test_chest_item_data_default_outfit_layer_is_one() -> void:
	var d: ChestItemData = ChestItemData.new()
	assert_eq(d.outfit_layer, 1)


func test_room_chest_config_reception_desk_has_three_items() -> void:
	var items: Array[ChestItemData] = RoomChestConfig.get_items("reception_desk")
	assert_eq(items.size(), 3)


func test_room_chest_config_unknown_id_returns_empty() -> void:
	var items: Array[ChestItemData] = RoomChestConfig.get_items("does_not_exist")
	assert_eq(items.size(), 0)


func test_room_chest_config_reception_desk_first_item_fields() -> void:
	var items: Array[ChestItemData] = RoomChestConfig.get_items("reception_desk")
	assert_eq(items[0].item_id, "clipboard")
	assert_eq(items[0].item_type, ChestItemData.ItemType.HOLDABLE)
	assert_eq(items[0].spawn_offset, Vector2(-70.0, -60.0))


func test_room_chest_config_patient_cabinet_stethoscope_outfit_layer_two() -> void:
	var items: Array[ChestItemData] = RoomChestConfig.get_items("patient_cabinet")
	var stethoscope: ChestItemData = items[1]
	assert_eq(stethoscope.item_id, "stethoscope")
	assert_eq(stethoscope.item_type, ChestItemData.ItemType.OUTFIT)
	assert_eq(stethoscope.outfit_layer, 2)


func test_are_items_spawned_false_initially() -> void:
	var chest: RoomChest = RoomChest.new()
	chest.chest_id = "reception_desk"
	add_child_autofree(chest)
	assert_false(chest.are_items_spawned())


func test_get_spawned_count_zero_initially() -> void:
	var chest: RoomChest = RoomChest.new()
	chest.chest_id = "reception_desk"
	add_child_autofree(chest)
	assert_eq(chest.get_spawned_count(), 0)


func test_get_item_config_count_matches_config() -> void:
	var chest: RoomChest = RoomChest.new()
	chest.chest_id = "reception_desk"
	add_child_autofree(chest)
	assert_eq(chest.get_item_config_count(), 3)


func test_spawn_items_creates_correct_count() -> void:
	var chest: RoomChest = RoomChest.new()
	chest.chest_id = "reception_desk"
	add_child_autofree(chest)
	chest.spawn_items()
	assert_eq(chest.get_spawned_count(), 3)


func test_double_spawn_is_noop() -> void:
	var chest: RoomChest = RoomChest.new()
	chest.chest_id = "reception_desk"
	add_child_autofree(chest)
	chest.spawn_items()
	chest.spawn_items()
	assert_eq(chest.get_spawned_count(), 3)


func test_receive_item_decrements_spawned_count() -> void:
	var chest: RoomChest = RoomChest.new()
	chest.chest_id = "reception_desk"
	add_child_autofree(chest)
	chest.spawn_items()
	var item: HoldableItem = chest.get_spawned_item(0)
	chest.receive_item(item)
	assert_eq(chest.get_spawned_count(), 2)


func test_get_press_position_returns_position_for_screen_touch_pressed() -> void:
	var chest: RoomChest = RoomChest.new()
	add_child_autofree(chest)
	var event: InputEventScreenTouch = InputEventScreenTouch.new()
	event.pressed = true
	event.position = Vector2(100.0, 200.0)
	assert_eq(chest._get_press_position(event), Vector2(100.0, 200.0))


func test_get_press_position_returns_inf_for_screen_touch_released() -> void:
	var chest: RoomChest = RoomChest.new()
	add_child_autofree(chest)
	var event: InputEventScreenTouch = InputEventScreenTouch.new()
	event.pressed = false
	event.position = Vector2(100.0, 200.0)
	assert_eq(chest._get_press_position(event), Vector2.INF)
