# Static helpers for res://scripts/isometric_follow_camera.gd (NEO-15 framing, NEO-17/28 guards).
extends GdUnitTestSuite

const IsoScript := preload("res://scripts/isometric_follow_camera.gd")
const ZoomBandConfigScript := preload("res://scripts/zoom_band_config.gd")
const OcclusionPolicyScript := preload("res://scripts/occlusion_policy.gd")


func test_desired_eye_matches_previous_static_camera_frame() -> void:
	var focus := Vector3(-5.0, 0.9, -5.0)
	var eye: Vector3 = IsoScript.desired_eye_world(
		focus, 25.709, deg_to_rad(20.693), deg_to_rad(45.0)
	)
	var want := Vector3(12.0, 10.0, 12.0)
	assert_that(eye.distance_to(want)).is_less(0.06)


func test_effective_follow_distance_fallback_when_config_null() -> void:
	assert_that(IsoScript.effective_follow_distance(null, 3, 12.5)).is_equal(12.5)


func test_effective_follow_distance_uses_config_when_valid() -> void:
	var cfg = ZoomBandConfigScript.new()
	cfg.band_distances = PackedFloat32Array([10.0, 20.0, 30.0])
	assert_that(IsoScript.effective_follow_distance(cfg, 1, 99.0)).is_equal(20.0)


func test_effective_follow_distance_clamps_band_index() -> void:
	var cfg = ZoomBandConfigScript.new()
	cfg.band_distances = PackedFloat32Array([10.0, 20.0])
	assert_that(IsoScript.effective_follow_distance(cfg, 99, 1.0)).is_equal(20.0)
	assert_that(IsoScript.effective_follow_distance(cfg, -3, 1.0)).is_equal(10.0)


func test_effective_follow_distance_empty_config_bands_falls_back() -> void:
	var cfg = ZoomBandConfigScript.new()
	cfg.band_distances = PackedFloat32Array()
	assert_that(IsoScript.effective_follow_distance(cfg, 0, 7.5)).is_equal(7.5)


func test_effective_follow_distance_fallback_when_band_non_positive() -> void:
	var cfg = ZoomBandConfigScript.new()
	cfg.band_distances = PackedFloat32Array([10.0, 0.0, 30.0])
	assert_that(IsoScript.effective_follow_distance(cfg, 2, 99.0)).is_equal(99.0)


func test_occlusion_policy_is_valid_null() -> void:
	assert_that(IsoScript.occlusion_policy_is_valid(null)).is_false()


func test_occlusion_policy_is_valid_wrong_script() -> void:
	var wrong = ZoomBandConfigScript.new()
	assert_that(IsoScript.occlusion_policy_is_valid(wrong)).is_false()


func test_occlusion_policy_is_valid_correct_script() -> void:
	var p = OcclusionPolicyScript.new()
	assert_that(IsoScript.occlusion_policy_is_valid(p)).is_true()


func test_occlusion_policy_is_valid_false_when_disabled() -> void:
	var p = OcclusionPolicyScript.new()
	p.enabled = false
	assert_that(IsoScript.occlusion_policy_is_valid(p)).is_false()


func test_occluder_override_key_is_valid_null() -> void:
	assert_that(IsoScript.occluder_override_key_is_valid(null)).is_false()


func test_occluder_override_key_is_valid_non_node() -> void:
	assert_that(IsoScript.occluder_override_key_is_valid(42)).is_false()


func test_occluder_override_key_is_valid_live_node3d() -> void:
	var n := Node3D.new()
	assert_that(IsoScript.occluder_override_key_is_valid(n)).is_true()
	n.free()


func test_occluder_override_key_is_valid_false_after_free() -> void:
	var n := Node3D.new()
	n.free()
	assert_that(IsoScript.occluder_override_key_is_valid(n)).is_false()
