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

const offerSchema = new mongoose.Schema({
  sender: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User',
    required: true
  },
  receiver: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User',
    required: true
  },
  status: {
    type: String,
    enum: ['pending', 'accepted', 'rejected'], // وضعیت درخواست
    default: 'pending'
  },
  transaction_id: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Payment',
    default: null
  }
})

offerSchema.plugin(timestamp)
offerSchema.plugin(mongoosePaginate)

const OfferModel = mongoose.model('Offer', offerSchema)
module.exports = OfferModel
