const mongoose = require('mongoose');

const teacherAttendanceSchema = new mongoose.Schema({
  teacherId: {
    type: String,
    required: true,
    ref: 'Teacher'
  },
  date: {
    type: Date,
    required: true,
    default: Date.now
  },
  status: {
    type: String,
    required: true,
    enum: ['Present', 'Late', 'Absent'],
    default: 'Absent'
  },
  notes: {
    type: String,
    trim: true,
    maxlength: 500
  },
  markedAt: {
    type: Date,
    default: Date.now
  },
  teacherName: {
    type: String,
    required: true
  },
  department: {
    type: String,
    required: true
  }
}, {
  timestamps: true
});

// Prevent duplicate attendance for same teacher on same date
teacherAttendanceSchema.index({ teacherId: 1, date: 1 }, { unique: true });

module.exports = mongoose.model('TeacherAttendance', teacherAttendanceSchema);