const mongoose = require('mongoose')
const timestamp = require('mongoose-timestamp')
const mongoosePaginate = require('mongoose-paginate-v2')

const ticketMessageSchema = new mongoose.Schema({
  text: { type: String, required: false },
  file: {
    type: String, // مسیر فایل در ذخیره شود
    required: false // فایل اختیاری است
  },
  senderType: { type: String, enum: ['User', 'Admin'], required: true },
  senderId: { type: mongoose.Schema.Types.ObjectId, refPath: 'senderType', required: true },
  ticket: { type: mongoose.Schema.Types.ObjectId, ref: 'Ticket', required: true }
})

ticketMessageSchema.plugin(timestamp)
// اضافه کردن پیجینیشن به مدل
ticketMessageSchema.plugin(mongoosePaginate)
const TicketMessageModel = mongoose.model('TicketMessage', ticketMessageSchema)
module.exports = TicketMessageModel
