const mongoose = require('mongoose');
const { Schema } = mongoose;
const chatSchema = new Schema({
sender: {
type: mongoose.Schema.Types.ObjectId,
refPath: 'senderModel',
required: true
},
senderModel: {
type: String,
required: true,
enum: ['user', 'business']
},
recipient: {
type: mongoose.Schema.Types.ObjectId,
refPath: 'recipientModel',
required: true
},
recipientModel: {
type: String,
required: true,
enum: ['user', 'business']
},
message: {
type: String,
required: true
},
timestamp: {
type: Date,
default: Date.now
},
isRead: {
type: Boolean,
default: false
}
}, { timestamps: true });
const Chat = mongoose.model('chat', chatSchema);
module.exports = Chat;