import type { CharacterAppearanceV1, CharacterHeldItemVisual } from "./characterAppearance";
import {
  weaponDefinition,
  weaponUsesBothHands,
  type CharacterBackPropModelId,
} from "./weaponCatalog";

export interface ResolvedCharacterEquipment {
  mainHand: CharacterHeldItemVisual;
  /** Effective render choice. The saved offhand remains untouched while hidden. */
  offHand?: CharacterHeldItemVisual;
  backPropModelId?: CharacterBackPropModelId;
  suppressSkinnedBack: boolean;
}

export function resolveCharacterEquipment(appearance: CharacterAppearanceV1): ResolvedCharacterEquipment {
  const crossbowEquipped = weaponDefinition(appearance.mainHand.modelId).category === "crossbow";
  return {
    mainHand: appearance.mainHand,
    ...(weaponUsesBothHands(appearance.mainHand.modelId) ? {} : appearance.offHand ? { offHand: appearance.offHand } : {}),
    ...(crossbowEquipped ? { backPropModelId: "cc/quiver" as const } : {}),
    suppressSkinnedBack: crossbowEquipped,
  };
}
