const { PrismaClient } = require('@prisma/client');

const prisma = new PrismaClient();

async function seed() {
  try {
    // Clear existing data
    await prisma.promo.deleteMany({});
    await prisma.promoCategory.deleteMany({});

    // Create categories
    const categories = [
      { name: 'New Member', slug: 'new-member' },
      { name: 'Monthly', slug: 'monthly' },
      { name: 'Package', slug: 'package' },
      { name: 'Special', slug: 'special' }
    ];
    for (const cat of categories) {
      await prisma.promoCategory.upsert({ where: { slug: cat.slug }, update: {}, create: cat });
    }

    // Create promos with periodStart and periodEnd
    const promos = [
      { title: 'Dine at Hyatt', slug: 'dine-at-hyatt', description: 'Promo spesial bulan ini', promoPrice: 'Promo Spesial', category: 'special', periodStart: '2026-07-01', periodEnd: '2026-07-31', featured: true, isActive: true },
      { title: 'Juli Glow Package', slug: 'juli-glow-package', description: 'Hydra Facial + Brightening Mask', promoPrice: 'Rp 999.000', normalPrice: 'Rp 1.798.000', discount: '44%', category: 'monthly', periodStart: '2026-07-01', periodEnd: '2026-07-31', featured: true, isActive: true },
      { title: 'Paket New Member Glowing', slug: 'paket-new-member-glowing', description: '1x Glow Facial + LED Therapy', promoPrice: 'Rp 399.000', normalPrice: 'Rp 749.000', discount: '47%', category: 'new-member', periodStart: '2026-01-01', periodEnd: '2026-12-31', featured: false, isActive: true },
      { title: 'First Visit Discount', slug: 'first-visit-discount', description: 'Diskon 30% untuk treatment pertama', promoPrice: '-30%', category: 'new-member', periodStart: '2026-01-01', periodEnd: '2026-12-31', featured: false, isActive: true },
      { title: 'Summer Body Ready', slug: 'summer-body-ready', description: '3x Body Slimming + 1x Body Bright', promoPrice: 'Rp 3.499.000', normalPrice: 'Rp 5.099.000', discount: '31%', category: 'monthly', periodStart: '2026-07-01', periodEnd: '2026-07-31', featured: false, isActive: true },
      { title: 'Carla Hair Free 6x', slug: 'carla-hair-free-6x', description: '6x Diode Laser Hair Removal', promoPrice: 'Rp 899.000', normalPrice: 'Rp 1.194.000', discount: '25%', category: 'package', periodStart: '2026-01-01', periodEnd: '2026-12-31', featured: false, isActive: true },
      { title: 'Carla Acne Fighter 6x', slug: 'carla-acne-fighter-6x', description: '6x Acne Laser + 6x Acne Facial', promoPrice: 'Rp 2.999.000', normalPrice: 'Rp 4.494.000', discount: '33%', category: 'package', periodStart: '2026-01-01', periodEnd: '2026-12-31', featured: false, isActive: true },
      { title: 'Carla Youth 4x', slug: 'carla-youth-4x', description: '4x Youth Laser + 4x Skin Booster', promoPrice: 'Rp 6.999.000', normalPrice: 'Rp 10.396.000', discount: '33%', category: 'package', periodStart: '2026-01-01', periodEnd: '2026-12-31', featured: false, isActive: true },
      { title: 'Carla Bridal Package', slug: 'carla-bridal-package', description: 'Complete pre-wedding beauty package', promoPrice: 'Rp 7.999.000', normalPrice: 'Rp 12.000.000', discount: '33%', category: 'package', periodStart: '2026-01-01', periodEnd: '2026-12-31', featured: false, isActive: true },
      { title: 'Birthday Treat', slug: 'birthday-treat', description: 'Diskon 50% di bulan ulang tahun', promoPrice: '-50%', category: 'special', periodStart: '2026-01-01', periodEnd: '2026-12-31', featured: false, isActive: true },
    ];

    for (const p of promos) {
      await prisma.promo.create({ data: p });
    }

    console.log('SUCCESS: Seed data berhasil! 10 promos created.');
  } catch (error) {
    console.error('ERROR:', error);
  } finally {
    await prisma.$disconnect();
  }
}

seed();
