import { MULTIPLAYER_MAPS } from '../public/js/menu-config.js';

const mapsById = new Map(MULTIPLAYER_MAPS.map((map) => [map.id, map]));

export function buildBotNavigationSmokePlan(mapIds) {
  if (!Array.isArray(mapIds) || new Set(mapIds).size !== mapIds.length) {
    throw new Error('bot navigation smoke requires unique map ids');
  }
  const plans = mapIds.map((id, index) => {
    const map = mapsById.get(id);
    if (!map || map.content !== 'retail') {
      throw new Error(`bot navigation smoke received an unknown retail map: ${id}`);
    }
    const mode = map.botModes.includes('DM')
      ? 'DM'
      : map.modes.includes('Team DM')
        ? 'Team DM'
        : map.modes[0];
    if (!mode) throw new Error(`bot navigation smoke has no compatible mode for ${id}`);
    return Object.freeze({
      id,
      mode,
      botCount: map.botModes.includes(mode) ? 1 : 0,
      index,
    });
  });
  plans.sort((left, right) => left.botCount - right.botCount || left.index - right.index);
  return plans.map(({ index: _index, ...plan }) => Object.freeze(plan));
}
