import mongoose from "mongoose";
import { connectDB } from "../server/utils/mongoose.js";
import dotenv from "dotenv";

// Load environment variables
dotenv.config();

// Import seed functions
import { execSync } from "child_process";

async function seedAll() {
  try {
    console.log("🌱 Starting database seeding...\n");

    // Seed members
    console.log("👥 Seeding members...");
    execSync("node scripts/seed-members.js", { stdio: "inherit" });

    console.log("\n🎉 Seeding events...");
    execSync("node scripts/seed-events.js", { stdio: "inherit" });

    console.log("\n📅 Seeding series events...");
    execSync("node scripts/seed-series-events.js", { stdio: "inherit" });

    console.log("\n✅ All data seeded successfully!");
    console.log("\n📊 Database Summary:");

    // Connect and show final counts
    await connectDB();

    const Member = (await import("../server/models/member.js")).default;
    const Event = (await import("../server/models/event.js")).default;

    const memberCount = await Member.countDocuments();
    const eventCount = await Event.countDocuments();

    console.log(`   Members: ${memberCount}`);
    console.log(`   Events: ${eventCount}`);

    process.exit(0);
  } catch (error) {
    console.error("❌ Error seeding database:", error);
    process.exit(1);
  }
}

seedAll();
