import Member from "../../../../models/member.js";

export default defineEventHandler(async (event) => {
  try {
    const body = await validateBody(event, seriesTicketEligibilitySchema);
    const { email } = body;

    const member = await Member.findOne({ email });

    if (!member) {
      return {
        isMember: false,
        message: "No membership found",
      };
    }

    return {
      isMember: true,
      circle: member.circle,
      name: member.name,
      email: member.email,
      message: "Member eligibility confirmed",
    };
  } catch (error) {
    console.error("Error checking series ticket eligibility:", error);
    throw createError({
      statusCode: 500,
      statusMessage: "Failed to check member eligibility",
    });
  }
});
