const mongoose = require('mongoose');

const messageSchema = new mongoose.Schema({
    conversation: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'Conversation',
        required: true,
      },
      sender: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'Account',
        required: true,
      },
      content: {
        type: String,
        required: true,
      },
      type: {
        type: String,
        required: true,
        enum: ['text', 'image', 'video', 'file'],
        default: 'text',
      },
      isRead: {
        type: Boolean,
        required: true,
        default: false,
      },
      attachments: {
        type: Array,
        required: false,
      },
      readAt: {
        type: Date,
        required: false,
      },
}, {
    timestamps: true,
    collection: 'messages'
})

module.exports = mongoose.model("Message", messageSchema);
