const mongoose = require('mongoose');

const employeeSchema = new mongoose.Schema({
  EmpFirstName: {
    type: String,
    required: [true, 'First name is required'],
    trim: true
  },
  EmpLastName: {
    type: String,
    required: [true, 'Last name is required'],
    trim: true
  },
  EmpGender: {
    type: String,
    required: [true, 'Gender is required'],
    enum: ['Male', 'Female', 'Other']
  },
  EmpDateOfBirth: {
    type: Date,
    required: [true, 'Date of birth is required']
  },
  EmpEmail: {
    type: String,
    required: [true, 'Email is required'],
    unique: true,
    lowercase: true,
    trim: true
  },
  EmpTelephone: {
    type: String,
    required: [true, 'Telephone is required'],
    trim: true
  },
  EmpAddress: {
    type: String,
    required: [true, 'Address is required'],
    trim: true
  },
  EmpHireDate: {
    type: Date,
    required: [true, 'Hire date is required']
  },
  EmpStatus: {
    type: String,
    required: [true, 'Status is required'],
    enum: ['Active', 'On Leave', 'Left', 'Blacklisted', 'Deceased', 'On Mission'],
    default: 'Active'
  },
  Department: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Department',
    default: null
  },
  Position: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Position',
    default: null
  }
}, { timestamps: true });

employeeSchema.virtual('fullName').get(function () {
  return `${this.EmpFirstName} ${this.EmpLastName}`;
});

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

module.exports = mongoose.model('Employee', employeeSchema);
