import { PrismaClient } from "@prisma/client"
import { PrismaPg } from "@prisma/adapter-pg"
import { Pool } from "pg"

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

// Même vidéo placeholder « atelier » réutilisée sur les autres drops en brouillon.
const WORKSHOP_VIDEO_URL = "https://www.youtube.com/embed/ORjlEpjiHrU"

async function main() {
  const collaborators = await db.collaborator.findMany({ select: { id: true, slug: true, name: true, role: true } })
  const graphiste = collaborators.find(
    (c) => c.slug.includes("graphiste") || c.role.toLowerCase().includes("graphiste") || c.role.toLowerCase().includes("branding")
  )
  if (!graphiste) {
    console.error("Collaborateur graphiste introuvable. Collaborateurs existants:", collaborators)
    process.exit(1)
  }
  const updatedCollab = await db.collaborator.update({
    where: { id: graphiste.id },
    data: { photo: "/drops/graphiste-avatar.jpg" },
  })
  console.log("OK, avatar mis à jour pour", updatedCollab.name, "->", updatedCollab.photo)

  const drop = await db.drop.findUnique({ where: { slug: "omt" } })
  if (!drop) {
    console.error("Drop O.M.T introuvable")
    process.exit(1)
  }
  const updatedDrop = await db.drop.update({
    where: { id: drop.id },
    data: { workshopVideoUrl: WORKSHOP_VIDEO_URL },
  })
  console.log("OK, vidéo atelier mise à jour pour", updatedDrop.name, "->", updatedDrop.workshopVideoUrl)
}

main()
  .catch((e) => {
    console.error(e)
    process.exit(1)
  })
  .finally(() => db.$disconnect())
