import mongoose from "mongoose";

// Define leave record schema
const leaveRecordSchema = new mongoose.Schema({
  date: {
    type: Date,
    required: true,
  },
  time: {
    type: String,
    required: true,
  },
  location: {
    type: String,
    // required: true,
  },
  reason: {
    type: String,
    required: true,
  },
  leaveType: {
    type: String,
    required: true,
    enum: ["Sick Leave", "Privilege Leave","Personal Leave"],
  },
});

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

export const Leave = mongoose.model("Leave", leaveSchema);
