/**
 * Poids par type/sous-type d'item (en kg)
 * Utilisé pour le calcul de charge inventaire joueur.
 * Clé : "item_type.item_subtype" ou "item_type" si pas de sous-type.
 */
export const ITEM_WEIGHTS: Record<string, number> = {
  // Documents (quasi nul)
  'document.fiche_paie': 0.001,
  'document.contrat': 0.001,
  'document.cle': 0.001,
  'document.carte': 0.001,
  'document.permis': 0.001,

  // Armes
  'arme.pistolet': 1,
  'arme.mitraillette': 2.5,
  'arme.fusil_assaut': 3.5,
  'arme.sniper': 6,
  'arme.lance_roquettes': 8,
  'arme.bazooka': 15,

  // Explosifs
  'explosif.grenade': 0.5,
  'explosif.charge': 1,

  // Accessoires
  'accessoire.montre': 0.1,
  'accessoire.chaine': 0.2,
  'accessoire.sac_a_dos': 1,

  // Nourriture / Drogues
  'nourriture': 0.3,
  'drogue': 0.2,

  // Objets de mission (poids moyens)
  'objet_mission.petit': 1.5,
  'objet_mission.moyen': 5,
  'objet_mission.gros': 12,
  'objet_mission.mallette': 7,
};

/**
 * Seuils de poids et malus associés
 */
export const WEIGHT_THRESHOLDS = {
  NORMAL_MAX: 15,        // 0-15 kg : aucun malus
  LIGHT_OVERLOAD: 25,    // 15-25 kg : +2% temps mission
  HEAVY_OVERLOAD: 35,    // 25-35 kg : +3% temps mission
  ABSOLUTE_MAX: 35,      // Au-delà : interdit
} as const;

export const BACKPACK_WEIGHT = 1; // kg
export const BACKPACK_COST = 50;  // ∞ lumière

/**
 * Calcule le malus mission basé sur le poids porté
 */
export function getWeightMalus(currentWeight: number, hasBackpack: boolean): number {
  if (hasBackpack) return 0; // Sac annule les malus
  if (currentWeight <= WEIGHT_THRESHOLDS.NORMAL_MAX) return 0;
  if (currentWeight <= WEIGHT_THRESHOLDS.LIGHT_OVERLOAD) return 0.02; // +2%
  if (currentWeight <= WEIGHT_THRESHOLDS.HEAVY_OVERLOAD) return 0.03; // +3%
  return -1; // Impossible (au-delà de 35kg)
}

/**
 * Récupère le poids d'un item par son type/sous-type
 */
export function getItemWeight(itemType: string, itemSubtype?: string): number {
  if (itemSubtype) {
    const key = `${itemType}.${itemSubtype}`;
    if (key in ITEM_WEIGHTS) return ITEM_WEIGHTS[key];
  }
  if (itemType in ITEM_WEIGHTS) return ITEM_WEIGHTS[itemType];
  return 0.5; // Default : 500g si type inconnu
}
