import { PrismaClient } from '@prisma/client';
import argon2 from 'argon2';

const prisma = new PrismaClient();

async function main() {
  // Hapus data lama dulu biar bersih
  await prisma.testimonial.deleteMany({});
  await prisma.promo.deleteMany({});
  await prisma.promoCategory.deleteMany({});
  await prisma.location.deleteMany({});
  await prisma.article.deleteMany({});

  // 1. Admin user (upsert)
  const hashedPassword = await argon2.hash('carla123');
  await prisma.user.upsert({
    where: { username: 'admin' },
    update: { password: hashedPassword },
    create: { username: 'admin', password: hashedPassword, role: 'admin' },
  });

  // 2. Promo Categories
  const categories = [
    { name: '🆕 New Member', slug: 'new-member' },
    { name: '📅 Bulanan', slug: 'monthly' },
    { name: '💳 Paket Hemat', slug: 'package' },
    { name: '🎁 Special Occasion', slug: 'special' },
  ];
  for (const cat of categories) {
    await prisma.promoCategory.upsert({
      where: { slug: cat.slug },
      update: {},
      create: cat,
    });
  }

  // 3. Treatment Categories
  const treatmentCats = [
    { name: 'Facial Treatment', slug: 'facial', description: 'Perawatan wajah komprehensif' },
    { name: 'Hair Removal', slug: 'hair-removal', description: 'Penghilangan bulu permanen' },
    { name: 'Brightening', slug: 'brightening', description: 'Pencerah kulit' },
    { name: 'Acne Treatment', slug: 'acne', description: 'Atasi masalah jerawat' },
    { name: 'Anti-Aging', slug: 'anti-aging', description: 'Anti-aging & lifting' },
    { name: 'Body Treatment', slug: 'body', description: 'Perawatan tubuh' },
  ];
  for (const tc of treatmentCats) {
    await prisma.treatmentCategory.upsert({ where: { slug: tc.slug }, update: {}, create: tc });
  }

  // 4. Treatments
  const treatments = [
    { name: 'Carla Basic Facial', slug: 'clara-basic-facial', category: 'facial', description: 'Pembersihan mendalam, ekstraksi komedo, masker, moisturizer.', benefits: 'Pembersihan mendalam||Eksfoliasi||Masker nutrisi||Moisturize' },
    { name: 'Carla Glow Facial', slug: 'clara-glow-facial', category: 'facial', description: 'Deep cleansing + serum Vitamin C + LED Light Therapy.', benefits: 'Vitamin C serum||LED therapy||Deep cleansing||Instant glow' },
    { name: 'IPL Hair Removal', slug: 'ipl-hair-removal', category: 'hair-removal', description: 'Intense Pulsed Light untuk mengurangi pertumbuhan bulu.', benefits: 'Minim rasa sakit||Hasil permanen||Cocok semua kulit' },
    { name: 'Diode Laser Hair Removal', slug: 'diode-laser-hair-removal', category: 'hair-removal', description: 'Gold standard hair removal.', benefits: 'Gold standard||Hasil maksimal||Semua jenis kulit' },
    { name: 'Carla Bright Laser', slug: 'clara-bright-laser', category: 'brightening', description: 'Laser Q-Switch untuk menghilangkan flek hitam.', benefits: 'Hilangkan flek||Meratakan warna||Presisi tinggi' },
    { name: 'Carla Acne Laser', slug: 'clara-acne-laser', category: 'acne', description: 'Laser diode khusus untuk membunuh bakteri penyebab jerawat.', benefits: 'Bunuh bakteri||Kurangi inflamasi||Kulit lebih bersih' },
    { name: 'Carla Lift (HIFU)', slug: 'clara-lift-hifu', category: 'anti-aging', description: 'High-Intensity Focused Ultrasound untuk mengencangkan kulit.', benefits: 'Lifting tanpa operasi||Mengencangkan kulit||Aman dan nyaman' },
    { name: 'Carla Body Slimming', slug: 'clara-body-slimming', category: 'body', description: 'Cryolipolysis untuk mengurangi lemak lokal tanpa operasi.', benefits: 'Pengurangan lemak||Tanpa operasi||Tidak ada downtime' },
  ];
  for (const t of treatments) {
    await prisma.treatment.upsert({ where: { slug: t.slug }, update: {}, create: t });
  }

  // 5. Articles
  const articles = [
    { title: '5 Kesalahan Skincare yang Sering Dilakukan Wanita Indonesia', slug: '5-kesalahan-skincare-wanita-indonesia', content: 'Skincare yang tepat adalah kunci...', excerpt: 'Memahami kesalahan skincare.', category: 'skincare', author: 'dr. Sarah Sp.KK', status: 'published' },
    { title: 'IPL vs Laser Hair Removal: Apa Bedanya?', slug: 'ipl-vs-laser-hair-removal', content: 'Ketika memilih hair removal treatment...', excerpt: 'Pelajari perbedaan antara IPL dan laser.', category: 'treatment', author: 'dr. Sarah Sp.KK', status: 'published' },
  ];
  for (const a of articles) {
    await prisma.article.upsert({ where: { slug: a.slug }, update: {}, create: a });
  }

  // 6. Locations
  const locations = [
    { name: 'Carla Skin Clinic — Senayan City', address: 'Senayan City Mall Lt.5', city: 'Jakarta Selatan', phone: '(021) 7278-1234', whatsapp: '0812-3456-7890', type: 'Skin Clinic', latitude: -6.2274, longitude: 106.7974 },
    { name: 'Carla Skin Clinic — Grand Indonesia', address: 'Grand Indonesia West Mall Lt.3A', city: 'Jakarta Pusat', phone: '(021) 3190-5000', whatsapp: '0812-3456-7891', type: 'Skin Clinic', latitude: -6.1945, longitude: 106.8157 },
  ];
  for (const l of locations) {
    await prisma.location.create({ data: l });
  }

  // 7. Promos - DENGAN SLUG, PERIOD START/END
  const promos = [
    {
      title: 'Dine at Hyatt',
      slug: 'dine-at-hyatt',
      description: 'Nikmati pengalaman eksklusif dengan promo spesial bulan ini. Treatment favorit Anda + voucher dining di Hyatt.',
      normalPrice: '',
      promoPrice: 'Promo Spesial',
      discount: '',
      periodStart: new Date('2026-07-01'),
      periodEnd: new Date('2026-07-31'),
      category: 'special',
      featured: true,
      isActive: true,
    },
    {
      title: 'Juli Glow Package',
      slug: 'juli-glow-package',
      description: 'Hydra Facial + Brightening Mask + Meso Glow',
      normalPrice: 'Rp 1.798.000',
      promoPrice: 'Rp 999.000',
      discount: '44%',
      periodStart: new Date('2026-07-01'),
      periodEnd: new Date('2026-07-31'),
      category: 'monthly',
      featured: true,
      isActive: true,
    },
    {
      title: 'Paket New Member Glowing',
      slug: 'paket-new-member-glowing',
      description: '1x Glow Facial + LED Therapy + Free Konsultasi + Skincare Kit',
      normalPrice: 'Rp 749.000',
      promoPrice: 'Rp 399.000',
      discount: '47%',
      periodStart: new Date('2026-01-01'),
      periodEnd: new Date('2026-12-31'),
      category: 'new-member',
      featured: false,
      isActive: true,
    },
    {
      title: 'First Visit Discount 30%',
      slug: 'first-visit-discount-30',
      description: 'Diskon 30% untuk treatment pertama (semua kategori)',
      normalPrice: 'Bervariasi',
      promoPrice: '-30%',
      discount: '30%',
      periodStart: new Date('2026-01-01'),
      periodEnd: new Date('2026-12-31'),
      category: 'new-member',
      featured: false,
      isActive: true,
    },
    {
      title: 'Summer Body Ready',
      slug: 'summer-body-ready',
      description: '3x Body Slimming + 1x Body Bright',
      normalPrice: 'Rp 5.099.000',
      promoPrice: 'Rp 3.499.000',
      discount: '31%',
      periodStart: new Date('2026-07-01'),
      periodEnd: new Date('2026-07-31'),
      category: 'monthly',
      featured: false,
      isActive: true,
    },
    {
      title: 'Carla Hair Free 6x',
      slug: 'carla-hair-free-6x',
      description: '6x Diode Laser Hair Removal (1 area)',
      normalPrice: 'Rp 1.194.000',
      promoPrice: 'Rp 899.000',
      discount: '25%',
      periodStart: new Date('2026-01-01'),
      periodEnd: new Date('2026-12-31'),
      category: 'package',
      featured: false,
      isActive: true,
    },
    {
      title: 'Carla Acne Fighter 6x',
      slug: 'carla-acne-fighter-6x',
      description: '6x Acne Laser + 6x Acne Facial',
      normalPrice: 'Rp 4.494.000',
      promoPrice: 'Rp 2.999.000',
      discount: '33%',
      periodStart: new Date('2026-01-01'),
      periodEnd: new Date('2026-12-31'),
      category: 'package',
      featured: false,
      isActive: true,
    },
    {
      title: 'Carla Youth 4x',
      slug: 'carla-youth-4x',
      description: '4x Youth Laser + 4x Skin Booster',
      normalPrice: 'Rp 10.396.000',
      promoPrice: 'Rp 6.999.000',
      discount: '33%',
      periodStart: new Date('2026-01-01'),
      periodEnd: new Date('2026-12-31'),
      category: 'package',
      featured: false,
      isActive: true,
    },
    {
      title: 'Carla Bridal Package',
      slug: 'carla-bridal-package',
      description: 'Complete pre-wedding beauty package (10 sesi)',
      normalPrice: 'Rp 12.000.000',
      promoPrice: 'Rp 7.999.000',
      discount: '33%',
      periodStart: new Date('2026-01-01'),
      periodEnd: new Date('2026-12-31'),
      category: 'package',
      featured: false,
      isActive: true,
    },
    {
      title: 'Birthday Treat',
      slug: 'birthday-treat',
      description: 'Diskon 50% di bulan ulang tahun (1 treatment)',
      normalPrice: 'Bervariasi',
      promoPrice: '-50%',
      discount: '50%',
      periodStart: new Date('2026-01-01'),
      periodEnd: new Date('2026-12-31'),
      category: 'special',
      featured: false,
      isActive: true,
    },
  ];
  for (const p of promos) {
    await prisma.promo.create({ data: p });
  }

  // 8. Testimonials
  const testimonials = [
    { name: 'Wika Cahyaningtyas', slug: 'wika-cahyaningtyas', text: 'Kemarin saya coba Photo Facial glow, diamond peel & underarm combo semua nya suka, hasilnya memuaskan. Dokter & staff nya pun menyenangkan. Pelayanannya ramah.', rating: 5, photo: 'https://i.pravatar.cc/80?img=1', position: 'Ibu Rumah Tangga', isActive: true },
    { name: 'Ellie Rosina', slug: 'ellie-rosina', text: 'Best service and treatments at Carla, selalu di update perkembangannya dan plan next treatmentnya biar lebih maksimal, semua staff & dokternya ramah.', rating: 5, photo: 'https://i.pravatar.cc/80?img=5', position: 'Pengusaha', isActive: true },
    { name: 'Poppy Ludovita', slug: 'poppy-ludovita', text: 'Semakin hari semakin on time, mengutamakan kenyamanan client, konsisten service nya. Sangat recommended untuk treatment kecantikan.', rating: 5, photo: 'https://i.pravatar.cc/80?img=9', position: 'Dokter', isActive: true },
    { name: 'Husna', slug: 'husna', text: 'Dari awal aku mempercayakan treatment wajah bersama Carla, semua dokter dan staff Carla selalu bikin aku merasa nyaman. Hal seperti ini yang tidak aku dapatkan di klinik lain.', rating: 4, photo: 'https://i.pravatar.cc/80?img=20', position: 'Karyawan Swasta', isActive: true },
  ];
  for (const t of testimonials) {
    await prisma.testimonial.upsert({
      where: { slug: t.slug },
      update: {},
      create: t,
    });
  }

  // 9. Doctors
  const doctors = [
    {
      name: 'dr. Sarah Sp.KK',
      slug: 'dr-sarah-sp-kk',
      title: 'Sp.KK',
      specialty: 'Dermatologi & Venereologi',
      bio: 'Dokter spesialis kulit dan kelamin dengan pengalaman lebih dari 15 tahun di bidang dermatologi kosmetik dan klinik. Ahli dalam penanganan jerawat, anti-aging, dan perawatan kulit canggih.',
      photo: 'https://i.pravatar.cc/150?img=10',
      education: 'FK Universitas Indonesia (S1)\nSpesialis Kulit & Kelamin (Sp.KK) - FKUI/RSCM\nFellowship Dermatologi Kosmetik - Singapore',
      experience: '15+ tahun pengalaman',
      services: JSON.stringify(['clara-basic-facial', 'clara-glow-facial', 'clara-acne-laser', 'clara-lift-hifu']),
      isActive: true,
      sortOrder: 1,
    },
    {
      name: 'dr. Maya Sp.KK',
      slug: 'dr-maya-sp-kk',
      title: 'Sp.KK',
      specialty: 'Dermatologi & Venereologi',
      bio: 'Dokter spesialis kulit dengan fokus pada dermatologi kosmetik dan laser. Berpengalaman menangani berbagai masalah kulit mulai dari jerawat, pigmentasi, hingga anti-aging.',
      photo: 'https://i.pravatar.cc/150?img=11',
      education: 'FK Universitas Padjadjaran (S1)\nSpesialis Kulit & Kelamin (Sp.KK) - FKUNPAD/RSHS\nSertifikasi Laser Dermatologi - ASLM',
      experience: '12+ tahun pengalaman',
      services: JSON.stringify(['clara-bright-laser', 'clara-acne-laser', 'clara-glow-facial']),
      isActive: true,
      sortOrder: 2,
    },
    {
      name: 'dr. Rina Sp.KK',
      slug: 'dr-rina-sp-kk',
      title: 'Sp.KK',
      specialty: 'Dermatologi & Venereologi',
      bio: 'Dokter spesialis kulit dengan keahlian pada laser estetika dan perawatan anti-aging. Memiliki pengalaman internasional di bidang dermatologi kosmetik.',
      photo: 'https://i.pravatar.cc/150?img=12',
      education: 'FK Universitas Airlangga (S1)\nSpesialis Kulit & Kelamin (Sp.KK) - FKUNAIR/RSHS\nFellowship Laser Dermatology - South Korea',
      experience: '10+ tahun pengalaman',
      services: JSON.stringify(['clara-lift-hifu', 'clara-bright-laser', 'clara-glow-facial']),
      isActive: true,
      sortOrder: 3,
    },
    {
      name: 'dr. Andi Sp.KK',
      slug: 'dr-andi-sp-kk',
      title: 'Sp.KK',
      specialty: 'Dermatologi & Venereologi',
      bio: 'Dokter spesialis kulit dengan fokus pada hair removal laser dan perawatan kulit pria. Ahli dalam diode laser dan teknologi penghilangan bulu permanen.',
      photo: 'https://i.pravatar.cc/150?img=13',
      education: 'FK Universitas Gadjah Mada (S1)\nSpesialis Kulit & Kelamin (Sp.KK) - FKUGM/RSHS\nSertifikasi Diode Laser Hair Removal',
      experience: '8+ tahun pengalaman',
      services: JSON.stringify(['ipl-hair-removal', 'diode-laser-hair-removal', 'clara-hair-free-6x']),
      isActive: true,
      sortOrder: 4,
    },
  ];
  for (const d of doctors) {
    await prisma.doctor.upsert({
      where: { slug: d.slug },
      update: {},
      create: d,
    });
  }

  console.log('✅ Seed data berhasil dibuat!');
  console.log('   - 4 Doctors');
  console.log('   - 10 Promos (2 featured) dengan slug & period range');
  console.log('   - 4 Promo Categories');
  console.log('   - 8 Treatments');
  console.log('   - 2 Articles');
  console.log('   - 2 Locations');
  console.log('   - 4 Testimonials');
  console.log('   - 4 Doctors');
}

main()
  .catch((e) => { console.error(e); process.exit(1); })
  .finally(async () => { await prisma.$disconnect(); });
