import mongoose from 'mongoose';

const studentSchema = new mongoose.Schema(
  {
    studentId: { type: String, required: true, unique: true },
    firstName: { type: String, required: true, trim: true },
    lastName: { type: String, required: true, trim: true },
    email: { type: String, lowercase: true, default: '' },
    phone: { type: String, default: '' },
    grade: { type: String, required: true },
    section: { type: String, default: 'A' },
    parentName: { type: String, default: '' },
    parentPhone: { type: String, default: '' },
    enrollmentDate: { type: Date, required: true },
    status: { type: String, enum: ['active', 'graduated', 'withdrawn'], default: 'active' },
    tuitionFee: { type: Number, required: true, default: 0 },
  },
  { timestamps: true }
);

studentSchema.virtual('fullName').get(function () {
  return `${this.firstName} ${this.lastName}`;
});

studentSchema.set('toJSON', { virtuals: true });
studentSchema.set('toObject', { virtuals: true });

export default mongoose.model('Student', studentSchema);
