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) })

async function main() {
  const all = await db.collaborator.findMany({ select: { id: true, slug: true, name: true, isAI: true } })
  const proto = all.find((c) => c.isAI)
  if (!proto) {
    console.error("Aucun collaborateur IA trouvé. Collaborateurs existants:", all)
    process.exit(1)
  }
  const updated = await db.collaborator.update({
    where: { id: proto.id },
    data: { photo: "/drops/proto-avatar.jpg" },
  })
  console.log("OK, avatar mis à jour pour", updated.name, "(slug:", updated.slug, ") ->", updated.photo)
}

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