const mongoose = require("mongoose");

const conversationSchema = new mongoose.Schema({
    user: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'Account',
        required: true,
      },
      admin: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'Account',
        required: false,
      },
      subject: {
        type: String,
        required: true,
      },
      roomId: {
        type: String,
        required: false,
      },
      status: {
        type: String,
        required: true,
        defaultValue: 'pending',
      },
      lastMessageAt: {
        type: Date,
        required: false,
      }
}, {
    timestamps: true,
    collection: 'conversations'
})

module.exports = mongoose.model("Conversation", conversationSchema);