const mongoose = require('mongoose');

const Schema = mongoose.Schema;

const orderSchema = new Schema(
    {
        userId: { type: Schema.Types.ObjectId, ref: 'user', required: true },
        productId: { type: Schema.Types.ObjectId, ref: 'Product', required: true },
        price: { type: Number, required: true },
        originalPrice: { type: Number },
        discountCode: { type: String },
        discountAmount: { type: Number, default: 0 },
        status: { type: String, enum: ['completed', 'failed'], default: 'completed' },
    },
    {
        timestamps: true,
    },
);

module.exports = mongoose.model('order', orderSchema);
