const mongoose = require('mongoose');

const CafeOrderDetailSchema = new mongoose.Schema(
  {
    orderId: { type: mongoose.Schema.Types.ObjectId, ref: 'CafeOrder', required: true },
    itemId: { type: mongoose.Schema.Types.ObjectId, ref: 'Item', required: true },
    quantity: { type: Number, required: true },
    kitchenServedQty: { type: Number, default: 0 },
    attachmentServedQty: { type: Number, default: 0 },
    attachmentServedAt: { type: Date, default: null },
    servedAt: { type: Date, default: null },
    specialNeeds: {
      type: [String], // An array of strings to store multiple names
      required: false, // The field is optional
    },
    itemTypeId: { type: mongoose.Schema.Types.ObjectId, required: false },
  },
  {
    timestamps: true, // Enables createdAt and updatedAt fields automatically
  }
);

const CafeOrderDetail = mongoose.model('CafeOrderDetail', CafeOrderDetailSchema);

module.exports = CafeOrderDetail;
