import { CapsuleShape3D } from "../../../../core/geom/3d/shape/CapsuleShape3D.js";
import { TransformedShape3D } from "../../../../core/geom/3d/shape/TransformedShape3D.js";
import { BodyKind } from "../../../physics/ecs/BodyKind.js";
import { Collider } from "../../../physics/ecs/Collider.js";
import { RigidBody } from "../../../physics/ecs/RigidBody.js";

/**
 * Spec-side helper: build the RigidBody + Collider pair the controller's
 * link() expects. Each test's makeWorld() can call this after
 * constructing the controller + transform, adding both components to
 * the entity builder before `.build(ecd)`.
 *
 * Capsule dimensions are loose — the prototype sizes them from
 * `cfg.body` but tests don't exercise the actual collision shape; what
 * matters for the controller's assert is that a RigidBody of the right
 * kind is present.
 *
 * @returns {{ rigidBody: RigidBody, collider: Collider }}
 */
export function buildTestPlayerBody() {
    const rigidBody = new RigidBody();
    rigidBody.kind = BodyKind.KinematicPosition;
    rigidBody.mass = 1;

    const collider = new Collider();
    // Capsule lives in [feet .. head] in world space — see the prototype's
    // buildPlayerEntity for the rationale. Wrap the centred CapsuleShape3D
    // in a TransformedShape3D with a +Y offset of half the body height
    // (1.8 / 2 = 0.9), matching prototype geometry.
    collider.shape = TransformedShape3D.from_translation(
        CapsuleShape3D.from(0.34, 1.12),
        [0, 0.9, 0],
    );

    return { rigidBody, collider };
}
