/**
 * Seed a fresh member in the right state to test the Welcome Workflow.
 * All onboarding flags default to false/null, no craft tags, no board topics.
 *
 * Usage: node scripts/seed-welcome-tester.js
 * Then pick "Welcome Tester" from the dev login dropdown.
 */
require("dotenv").config();
const mongoose = require("mongoose");

async function main() {
  await mongoose.connect(process.env.MONGODB_URI);

  const Member = mongoose.connection.model(
    "Member",
    new mongoose.Schema({}, { strict: false, collection: "members" }),
  );

  const email = "welcome-tester@ghostguild.dev";

  const result = await Member.findOneAndUpdate(
    { email },
    {
      $set: {
        name: "Welcome Tester",
        email,
        circle: "community",
        contributionAmount: 0,
        role: "member",
        status: "active",
        craftTags: [],
        board: { topics: [], offerPeerSupport: false },
        onboarding: {
          completedAt: null,
          eventPageVisited: false,
          boardPageVisited: false,
          wikiClicked: false,
        },
      },
    },
    { upsert: true, new: true },
  );

  console.log(`Seeded member: ${result.name} (${result.email}) — _id: ${result._id}`);
  console.log("All onboarding flags reset. Pick 'Welcome Tester' from the dev dropdown.");
  await mongoose.disconnect();
}

main().catch((err) => {
  console.error(err);
  process.exit(1);
});
