import { PrismaClient } from "@prisma/client";
import bcrypt from "bcryptjs";

const prisma = new PrismaClient();

async function main() {
  const pw = process.argv[2];
  if (!pw) {
    console.error("usage: tsx scripts/seed-password.ts <password>");
    process.exit(1);
  }
  const hash = await bcrypt.hash(pw, 10);
  await prisma.setting.upsert({
    where: { key: "auth.passwordHash" },
    create: { key: "auth.passwordHash", value: hash },
    update: { value: hash },
  });
  console.log("ok");
}

main().finally(() => prisma.$disconnect());
