import { PrismaClient } from '@prisma/client'
import { PrismaPg } from '@prisma/adapter-pg'
import pg from 'pg'
import "dotenv/config";

const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL })
const adapter = new PrismaPg(pool)
const prisma = new PrismaClient({ adapter })

async function main() {
  console.log('Seeding blog posts...')

  // Clear existing posts to avoid unique constraint issues on slug during re-seed
  try {
    await prisma.post.deleteMany({})
    console.log('Cleaned existing posts.')
  } catch (err) {
    console.log('Skipping deleteMany, table might not exist yet.')
  }

  const posts = [
    {
      title: "Ören'in Gizli Cevherleri: Akbük ve Ötesi",
      slug: "orenin-gizli-cevherleri",
      excerpt: "Sadece yerellerin bildiği, turkuaz suları ve sakinliği ile büyüleyen o gizli koyları keşfedin.",
      content: "Ören Mahallesi'nin kalbinde yer alan Ayris Apart'tan çıktığınızda, sizi sadece bir deniz değil, binlerce yıllık bir hikaye karşılar. Akbük Koyu'nun dinginliğinden Alatepe'nin yamaç paraşütü heyecanına kadar, bu rehberimizde Ören'in en özel noktalarını derledik...",
      image: "https://res.cloudinary.com/du7xohbct/image/upload/v1776642502/ayrisapart/experiences/oren_d2pxcy.jpg",
      lang: "tr",
      published: true,
      author: "Ayris Ekibi"
    },
    {
      title: "Hidden Gems of Oren: Akbuk and Beyond",
      slug: "hidden-gems-of-oren",
      excerpt: "Discover the secret coves known only to locals, enchanting with their turquoise waters and serenity.",
      content: "When you step out of Ayris Apart, located in the heart of Oren, you are greeted not just by a sea, but by a story of thousands of years. From the serenity of Akbuk Bay to the paragliding excitement of Alatepe, we have compiled the most special spots of Oren in this guide...",
      image: "https://res.cloudinary.com/du7xohbct/image/upload/v1776642502/ayrisapart/experiences/oren_d2pxcy.jpg",
      lang: "en",
      published: true,
      author: "Ayris Team"
    },
    {
      title: "Ayris Apart'ta Mimari ve Konfor",
      slug: "mimari-ve-konfor",
      excerpt: "Modern tasarımın mitolojik isimlerle buluştuğu suitlerimizin hikayesini keşfedin.",
      content: "Ayris Apart sadece bir konaklama noktası değil, bir yaşam alanıdır. Her bir suitimizin ismi (Iris, Electra, Arke...) Yunan mitolojisinden esinlenerek seçildi. Bu yazımızda, odalarımızın dekorasyonunda kullandığımız malzemeleri ve tasarım felsefemizi anlatıyoruz...",
      image: "https://res.cloudinary.com/du7xohbct/image/upload/v1776641696/ayrisapart/hero/1_cxfvrw.jpg",
      lang: "tr",
      published: true,
      author: "Tasarım Ekibi"
    },
    {
      title: "Architecture and Comfort at Ayris Apart",
      slug: "architecture-and-comfort",
      excerpt: "Discover the story of our suites where modern design meets mythological names.",
      content: "Ayris Apart is not just an accommodation point, it is a living space. The name of each of our suites (Iris, Electra, Arke...) was chosen inspired by Greek mythology. In this article, we describe the materials we use in the decoration of our rooms and our design philosophy...",
      image: "https://res.cloudinary.com/du7xohbct/image/upload/v1776641696/ayrisapart/hero/1_cxfvrw.jpg",
      lang: "en",
      published: true,
      author: "Design Team"
    }
  ]

  for (const post of posts) {
    await prisma.post.create({
      data: post
    })
    console.log(`Created post: ${post.title}`)
  }

  console.log('Seed completed successfully!')
}

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