import { DataSource } from 'typeorm';
import { Achievement } from '../achievement/achievement.entity';

const ACHIEVEMENTS_DATA = [
  // Combat
  { key: 'combat_10', name: 'Apprenti Guerrier', description: 'Remporter 10 combats', category: 'combat', tier: 'bronze', criteriaType: 'combat_wins', criteriaValue: 10, rewardGold: 50, rewardTitle: null },
  { key: 'combat_100', name: 'Guerrier Aguerri', description: 'Remporter 100 combats', category: 'combat', tier: 'silver', criteriaType: 'combat_wins', criteriaValue: 100, rewardGold: 200, rewardTitle: 'Guerrier Aguerri' },
  { key: 'combat_1000', name: 'Légende du Combat', description: 'Remporter 1000 combats', category: 'combat', tier: 'gold', criteriaType: 'combat_wins', criteriaValue: 1000, rewardGold: 1000, rewardTitle: 'Légende' },

  // Progression
  { key: 'level_10', name: 'Aventurier', description: 'Atteindre le niveau 10', category: 'progression', tier: 'bronze', criteriaType: 'level_reached', criteriaValue: 10, rewardGold: 100, rewardTitle: null },
  { key: 'level_50', name: 'Héros', description: 'Atteindre le niveau 50', category: 'progression', tier: 'silver', criteriaType: 'level_reached', criteriaValue: 50, rewardGold: 500, rewardTitle: 'Héros' },
  { key: 'level_100', name: 'Légende Vivante', description: 'Atteindre le niveau 100', category: 'progression', tier: 'gold', criteriaType: 'level_reached', criteriaValue: 100, rewardGold: 2000, rewardTitle: 'Légende Vivante' },

  // Economy
  { key: 'gold_1000', name: 'Marchand', description: 'Accumuler 1 000 pièces d\'or', category: 'economy', tier: 'bronze', criteriaType: 'gold_accumulated', criteriaValue: 1000, rewardGold: 100, rewardTitle: null },
  { key: 'gold_10000', name: 'Négociant', description: 'Accumuler 10 000 pièces d\'or', category: 'economy', tier: 'silver', criteriaType: 'gold_accumulated', criteriaValue: 10000, rewardGold: 500, rewardTitle: 'Négociant' },
  { key: 'gold_100000', name: 'Magnat', description: 'Accumuler 100 000 pièces d\'or', category: 'economy', tier: 'gold', criteriaType: 'gold_accumulated', criteriaValue: 100000, rewardGold: 2000, rewardTitle: 'Magnat' },

  // Equipment — Forge
  { key: 'forge_5', name: 'Apprenti Forgeron', description: 'Réussir 5 améliorations de forge', category: 'equipment', tier: 'bronze', criteriaType: 'forge_upgrades', criteriaValue: 5, rewardGold: 100, rewardTitle: null },
  { key: 'forge_25', name: 'Maître Forgeron', description: 'Réussir 25 améliorations de forge', category: 'equipment', tier: 'silver', criteriaType: 'forge_upgrades', criteriaValue: 25, rewardGold: 500, rewardTitle: 'Maître Forgeron' },
  { key: 'forge_100', name: 'Forgeron Légendaire', description: 'Réussir 100 améliorations de forge', category: 'equipment', tier: 'gold', criteriaType: 'forge_upgrades', criteriaValue: 100, rewardGold: 2000, rewardTitle: 'Forgeron Légendaire' },

  // Equipment — Craft
  { key: 'craft_5', name: 'Artisan Novice', description: 'Compléter 5 crafts', category: 'equipment', tier: 'bronze', criteriaType: 'craft_completed', criteriaValue: 5, rewardGold: 75, rewardTitle: null },
  { key: 'craft_25', name: 'Artisan Confirmé', description: 'Compléter 25 crafts', category: 'equipment', tier: 'silver', criteriaType: 'craft_completed', criteriaValue: 25, rewardGold: 300, rewardTitle: 'Artisan' },
  { key: 'craft_100', name: 'Grand Artisan', description: 'Compléter 100 crafts', category: 'equipment', tier: 'gold', criteriaType: 'craft_completed', criteriaValue: 100, rewardGold: 1500, rewardTitle: 'Grand Artisan' },
];

export async function seedAchievements(dataSource: DataSource) {
  const repo = dataSource.getRepository(Achievement);

  for (const data of ACHIEVEMENTS_DATA) {
    const existing = await repo.findOne({ where: { key: data.key } });
    if (!existing) {
      await repo.save(repo.create(data));
    }
  }

  console.log(`✅ ${ACHIEVEMENTS_DATA.length} achievements seedés`);
}
