const mongoose = require('mongoose');

const departmentSchema = new mongoose.Schema({
  DepartName: {
    type: String,
    required: [true, 'Department name is required'],
    unique: true,
    trim: true
  }
}, { timestamps: true });

departmentSchema.virtual('employees', {
  ref: 'Employee',
  localField: '_id',
  foreignField: 'Department'
});

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

module.exports = mongoose.model('Department', departmentSchema);
