const mongoose = require('mongoose');

const MessageSchema = new mongoose.Schema(
    {
        sender: {
            type: mongoose.Schema.Types.ObjectId,
            ref: 'User',
            required: true,
        },
        receiver: {
            type: mongoose.Schema.Types.ObjectId,
            ref: 'User',
            required: true,
        },
        order: { // تأكد من الاسم هنا
            type: mongoose.Schema.Types.ObjectId,
            ref: 'Order',
            required: true,
        },
        text: {
            type: String,
            required: true,
        },
        tempId: {
            type: String, // To sync optimistic UI messages
        },
        isRead: {
            type: Boolean,
            default: false,
        },
    },
    { timestamps: true }
);

module.exports = mongoose.model('Message', MessageSchema);