import { ATTUNEMENTS_DEF } from '../data/attunements';
import { getGuardianForFloor } from '../data/guardian-encounters';

/** Build pact element map and gross regen for the unified conversion system */
export function buildConversionParams(
  signedPacts: number[],
  attunements: Record<string, { active: boolean; level: number }>,
): { pactElementMap: Record<number, string>; grossRegen: Record<string, number> } {
  const pactElementMap: Record<number, string> = {};
  for (const floor of signedPacts) {
    const guardian = getGuardianForFloor(floor);
    if (guardian?.element?.length) {
      pactElementMap[floor] = guardian.element[0];
    }
  }
  const grossRegen: Record<string, number> = {};
  for (const [id, state] of Object.entries(attunements)) {
    if (!state.active) continue;
    const def = ATTUNEMENTS_DEF[id];
    if (def?.primaryManaType && def.rawManaRegen) {
      const levelMult = Math.pow(1.5, (state.level || 1) - 1);
      grossRegen[def.primaryManaType] = (grossRegen[def.primaryManaType] || 0)
        + def.rawManaRegen * levelMult;
    }
  }
  return { pactElementMap, grossRegen };
}
