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

const paymentSchema = new mongoose.Schema({
  amount: {
    type: Number,
    required: true
  },
  status: {
    type: String,
    enum: ['pending', 'successful', 'failed'],
    default: 'pending'
  },
  authority: {
    type: String,
    required: false
  },
  user_id: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User'
  },
  project_id: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Project'
  },
  advertising_id: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Advertising'
  },
  type: {
    type: String,
    required: true
  },
  installment_step: {
    type: String,
    required: false,
    default: null
  }
})

paymentSchema.plugin(timestamp)
paymentSchema.plugin(mongoosePaginate)

const PaymentModel = mongoose.model('Payment', paymentSchema)
module.exports = PaymentModel
