import Member from "../../models/member.js";
import { connectDB } from "../../utils/mongoose.js";

export default defineEventHandler(async () => {
  if (
    process.env.NODE_ENV === "production" &&
    process.env.ALLOW_DEV_TEST_ENDPOINTS !== "true"
  ) {
    throw createError({ statusCode: 404, statusMessage: "Not found" });
  }

  await connectDB();

  const members = await Member.find({}, "name email circle role status")
    .sort({ name: 1 })
    .lean();

  return members.map((m) => ({
    label: `${m.name} (${m.email})`,
    value: m.email,
    circle: m.circle,
    role: m.role,
  }));
});
