import type { Quat, Vec3 } from "./math.js";

/**
 * Collision filter categories.
 *
 * box3d-wasm exposes `{categoryBits, maskBits}` filters on shapes and raycasts.
 * The character mover raycasts against WORLD|PROP only, so it never snags on
 * sensors or on its own capsule.
 */
export const CollisionGroup = {
  WORLD: 0x0001,
  PLAYER: 0x0002,
  ENEMY: 0x0004,
  PROP: 0x0008,
  TRIGGER: 0x0010,
  CAMERA_ZONE: 0x0020,
} as const;

export type CollisionGroupName = keyof typeof CollisionGroup;

export interface CollisionFilter {
  categoryBits: number;
  maskBits: number;
}

/** Everything the character mover is allowed to stand on or bump into. */
export const MOVER_SOLID_MASK = CollisionGroup.WORLD | CollisionGroup.PROP;

/**
 * Collider primitives.
 *
 * Deliberately limited to what box3d-wasm@0.2.0 binds: box, sphere, capsule and
 * convex hull. Upstream Box3D has no triangle-mesh shape in this build, so room
 * geometry is authored as a compound of these rather than as a trimesh (GDD §7
 * assumes trimesh support that does not exist yet).
 */
export type ColliderDef =
  | { kind: "box"; halfExtents: Vec3; offset?: Vec3; rotation?: Quat }
  | { kind: "sphere"; radius: number; offset?: Vec3 }
  | { kind: "capsule"; radius: number; height: number; offset?: Vec3 }
  | { kind: "hull"; points: Vec3[]; offset?: Vec3 };

export interface ColliderMaterial {
  friction?: number;
  restitution?: number;
  density?: number;
}
