import 'reflect-metadata';
import { AppDataSource } from './data-source';
import { LevelThreshold } from '../character/entities/level-threshold.entity';

async function seed() {
  await AppDataSource.initialize();
  console.log('DB connectée (MySQL)');

  const repo = AppDataSource.getRepository(LevelThreshold);
  const existing = await repo.count();

  if (existing >= 100) {
    console.log('Level thresholds déjà seedés — skip');
    await AppDataSource.destroy();
    return;
  }

  // XP requis = 100 × level^1.5
  const thresholds: LevelThreshold[] = Array.from({ length: 100 }, (_, i) => {
    const level = i + 1;
    const threshold = new LevelThreshold();
    threshold.level = level;
    threshold.xpRequired = Math.round(100 * Math.pow(level, 1.5));
    return threshold;
  });

  await repo.save(thresholds);
  console.log('✅ 100 level_thresholds seedés');

  await AppDataSource.destroy();
}

seed().catch((err) => {
  console.error('Seed échoué :', err);
  process.exit(1);
});
