const mongoose = require('mongoose');

const orderSchema = new mongoose.Schema({
    user: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'Account',
        required: true,
      },
      totalAmount: {
        type: Number,
        required: true,
      },
      amountPaid: {
        type: Number,
        required: true,
        default: 0,
      },
      swapped: {
        type: Boolean,
        required: true,
        default: false,
      },
      swap: {
        type: Array,
        required: false,
      },
      address: {
        type: String,
        required: true,
      },
      status: {
        type: String,
        required: true,
        enum: ['pending', 'completed', 'cancelled', 'rejected', 'accepted', 'partially paid', 'paid', 'in progress'],
        default: 'pending',
      },
      paymentCompleted: {
        type: Boolean,
        required: true,
        default: false,
      },
      paymentMode: {
        type: String,
        required: true,
        enum: ['installment', 'full'],
        default: 'full',
      },      
}, {
    timestamps: true,
    collection: 'orders'
})

module.exports = mongoose.model("Order", orderSchema);