import 'dotenv/config';
import { db, initDB } from './src/core/db.js';

await initDB();

const GUILD_ID = process.env.DEV_GUILD_ID || process.env.OWNER_ID; // Ganti dengan guild ID kamu

console.log('🔧 Setting up Discord Premium products...');

// 1. Buat kategori "Discord App"
let category = db.prepare('SELECT id FROM categories WHERE guild_id = ? AND name = ?').get(GUILD_ID, 'Discord App');
if (!category) {
  const r = db.prepare('INSERT INTO categories (guild_id, name, emoji, description) VALUES (?, ?, ?, ?)')
    .run(GUILD_ID, 'Discord App', '💎', 'Discord Nitro & Premium');
  category = { id: r.lastInsertRowid };
  console.log(`✅ Kategori "Discord App" dibuat (ID: ${category.id})`);
} else {
  console.log(`ℹ️  Kategori "Discord App" sudah ada (ID: ${category.id})`);
}

// 2. Tambah produk Discord Premium dengan gambar Nitro
const products = [
  {
    name: 'Discord Nitro (1 Bulan)',
    description: 'Nitro full features: custom emoji, HD streaming, server boost, profile banner',
    price: 50000,
    image_url: 'https://cdn.discordapp.com/emojis/1096190031948214272.png',
  },
  {
    name: 'Discord Nitro (1 Tahun)',
    description: 'Nitro 12 bulan - hemat 20%',
    price: 500000,
    image_url: 'https://cdn.discordapp.com/emojis/1096190031948214272.gif',
  },
  {
    name: 'Discord Nitro Basic (1 Bulan)',
    description: 'Custom emoji, upload 50MB, HD video - tanpa server boost',
    price: 30000,
    image_url: 'https://i.imgur.com/QbJjHVP.png',
  },
];

for (const p of products) {
  const existing = db.prepare('SELECT id FROM products WHERE guild_id = ? AND name = ?').get(GUILD_ID, p.name);
  if (existing) {
    console.log(`⏭️  "${p.name}" sudah ada (ID: ${existing.id})`);
    continue;
  }

  const r = db.prepare(`
    INSERT INTO products (guild_id, category_id, name, description, price, image_url, auto_delivery)
    VALUES (?, ?, ?, ?, ?, ?, 1)
  `).run(GUILD_ID, category.id, p.name, p.description, p.price, p.image_url);

  console.log(`✅ "${p.name}" dibuat (ID: ${r.lastInsertRowid})`);
}

console.log('\n🎉 Setup selesai! Jalankan:');
console.log('   /store panel channel:#products');
console.log('   atau kirim via dashboard API');

process.exit(0);
