class_name M2BuildBatchPlanner
extends RefCounted

## Stateless M2 build batch sizing and group-cursor progression.


## Plans one static or animated build batch. The returned Dictionary is detached
## and contains effective_batch_size, batch_count, next_offset and group_complete.
func plan_batch(
		transform_count: int,
		current_offset: int,
		has_animated_prototype: bool,
		animated_batch_limit: int,
		static_batch_limit: int
) -> Dictionary:
	var selected_batch_limit := (
		animated_batch_limit if has_animated_prototype else static_batch_limit
	)
	var effective_batch_size := maxi(1, selected_batch_limit)
	var remaining_transform_count := maxi(0, transform_count - current_offset)
	var batch_count := mini(effective_batch_size, remaining_transform_count)
	var is_group_complete := (
		batch_count <= 0 or current_offset + batch_count >= transform_count
	)
	return {
		"effective_batch_size": effective_batch_size,
		"batch_count": batch_count,
		"next_offset": 0 if is_group_complete else current_offset + batch_count,
		"group_complete": is_group_complete,
	}
