import mongoose from "mongoose";

const ApplicationSchema = new mongoose.Schema(
  {
    fullName: { type: String, required: true, trim: true },
    email: { type: String, required: true, trim: true, lowercase: true },
    phone: { type: String, trim: true },
    jobId: { type: mongoose.Schema.Types.ObjectId, ref: "Job", required: true },
    role: { type: String, required: true, trim: true }, // Job title for quick reference
    location: { type: String, required: true, trim: true },
    resumeUrl: { type: String, trim: true },
    note: { type: String, trim: true },
    status: {
      type: String,
      required: true,
      enum: ["New", "Reviewed", "Interview", "Rejected"],
      default: "New",
    },
    avatar: { type: String, trim: true },
  },
  { timestamps: true }
);

ApplicationSchema.index({ jobId: 1, createdAt: -1 });
ApplicationSchema.index({ status: 1 });
ApplicationSchema.index({ email: 1 });

const ApplicationModel = mongoose.models.Application || mongoose.model("Application", ApplicationSchema);

export { ApplicationModel };

