import mongoose from "mongoose";

const UserResumeSchema = new mongoose.Schema(
  {
    fullName: { type: String, required: true, trim: true },
    email: { type: String, required: true, trim: true, lowercase: true },
    phoneNumber: { type: String, required: true, trim: true },
    cvURL: { type: String, required: true, trim: true },
    coverNote: { type: String, trim: true },
    jobId: { type: mongoose.Schema.Types.ObjectId, ref: "Job", required: false },
    positionTitle: { type: String, trim: true },
  },
  { timestamps: true }
);

UserResumeSchema.index({ email: 1 });
UserResumeSchema.index({ createdAt: -1 });

// Try to use existing model first, then create new one
// Let Mongoose use default collection name "userresumes" (pluralized from "UserResume")
// If collection name is different in your database, you can override it by setting the third parameter
const UserResumeModel = mongoose.models.UserResume || mongoose.model("UserResume", UserResumeSchema);

export { UserResumeModel };

