const mongoose = require("mongoose");
const Schema = mongoose.Schema;

const orderSchema = new Schema ({
    userId:{
        type: Schema.Types.ObjectId,
        ref: "User",
        required: true,
    },
    adminId: {
        type: Schema.Types.ObjectId,
        ref: "Admin",
        required: true
    },
    shopId:{
        type: Schema.Types.ObjectId,
        ref: "Shop",
        required: true
    },
    product:[{
        productId: {
            type: Schema.Types.ObjectId,
            ref: "Product",
            required: true
        },
        quantity:{
            type: Number,
            requried: true
        } 
    }],
    date:{
        type: String,
        required: true
    },
    subTotal: {
        type: Number,
        required: true,
    },
    couponDiscount :{
        type: Number,
        required: true
    },
    salesTax: {
        type: Number,
        required: true,
    },
    platFormCharges: {
        type: Number,
        required: true 
    },
    grandTotal: {
        type: Number,
        required: true
    },
    status:{
        type: String,
        enum: ["Pending", "Preparing", "Picked", "Delivered", "Rejected"],
        default: "Pending"
    },
    transactionId:{
        type: String
    },
    transactionStatus: {
        type: String,
        enum: ["Approved", "Declined", "Failed", "Refunded"]
    }
});

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