import mongoose from 'mongoose';

// Define attendance record schema
const attendanceRecordSchema = new mongoose.Schema({
  date: {
    type: Date,
    required: true,
  },
  time: {
    type: String,
    required: true,
  },
  location: {
    type: String,
    required: true,
  },
  notes: {
    type: String,
  },
});

// Define main attendance schema
const attendanceSchema = new mongoose.Schema({
  userId: {
    type: mongoose.Schema.Types.ObjectId,
    refPath: 'userType',
    required: true,
  },
  userType: {
    type: String,
    required: true,
    enum: ['SalesCoOrdinator', 'TerritoryManager'],
  },
  records: [attendanceRecordSchema],
}, { timestamps: true, versionKey: false });

export const Attendance = mongoose.model('Attendance', attendanceSchema);
