import mongoose from "mongoose";

const preRegistrationSchema = new mongoose.Schema(
  {
    email: {
      type: String,
      required: true,
      unique: true,
      lowercase: true,
      trim: true,
    },
    name: String,
    city: String,
    role: String, // professional role (e.g. "3D artist") — admin-only reference
    newsletterOptIn: Boolean,
    status: {
      type: String,
      enum: ["pending", "selected", "invited", "accepted", "expired"],
      default: "pending",
    },
    inviteEmailSentAt: Date,
    acceptedAt: Date,
    memberId: { type: mongoose.Schema.Types.ObjectId, ref: "Member" },
    magicLinkJti: String,
    magicLinkJtiUsed: { type: Boolean, default: false },
    adminNotes: String,
  },
  { timestamps: true }
);

export default mongoose.models.PreRegistration ||
  mongoose.model("PreRegistration", preRegistrationSchema);
