const FAKE_NAMES = ['alex.tk', 'mia_live', 'coach_pro', 'zed99', 'luna.fr', 'kevin_du42', 'sara.live'];
const FAKE_GIFTS = [
  { name: 'Rose', diamonds: 1 },
  { name: 'Coeur', diamonds: 5 },
  { name: 'Lion', diamonds: 500 },
  { name: 'Univers', diamonds: 1000 }
];

function pick(arr) {
  return arr[Math.floor(Math.random() * arr.length)];
}

/**
 * Genere de faux evenements TikTok pour developper/tester les jeux sans etre en live.
 * Retourne une fonction stop().
 */
function startSimulation(onEvent) {
  const timers = [];

  timers.push(setInterval(() => {
    onEvent({ type: 'like', uniqueId: pick(FAKE_NAMES), likeCount: 1 + Math.floor(Math.random() * 10) });
  }, 800));

  timers.push(setInterval(() => {
    const gift = pick(FAKE_GIFTS);
    onEvent({ type: 'gift', uniqueId: pick(FAKE_NAMES), giftName: gift.name, diamondCount: gift.diamonds, repeatCount: 1 });
  }, 4000));

  timers.push(setInterval(() => {
    onEvent({ type: 'follow', uniqueId: pick(FAKE_NAMES) });
  }, 6000));

  return () => timers.forEach(clearInterval);
}

module.exports = { startSimulation };
