const bcrypt = require("bcrypt");
const { query } = require("./db");

const users = [
  { username: "hop", password: "hopmusic2025" },
  { username: "kristen", password: "kristen2025" },
  { username: "camilah", password: "camilah2025" },
  { username: "worship-leader", password: "worship2025" },
];

async function updatePasswords() {
  console.log("🔐 Updating user passwords with bcrypt hashes...\n");

  for (const user of users) {
    try {
      // Generate bcrypt hash
      const hash = await bcrypt.hash(user.password, 10);

      // Update in database
      await query(
        "UPDATE users SET password_hash = $1 WHERE LOWER(username) = LOWER($2)",
        [hash, user.username],
      );

      console.log(`✅ Updated password for: ${user.username}`);
    } catch (err) {
      console.error(`❌ Failed to update ${user.username}:`, err.message);
    }
  }

  console.log("\n✨ Password update complete!");
  process.exit(0);
}

updatePasswords().catch((err) => {
  console.error("Error:", err);
  process.exit(1);
});
