import mongoose from "mongoose"; // Define Product record schema const ProductRecordSchema = new mongoose.Schema({ productid: { type: mongoose.Schema.Types.ObjectId, ref: "Product", required: true, }, SKU: { type: String, }, openingInventory: { type: Number, default: 0, }, Stock: { type: Number, default: 0, }, }); // Define main Stock schema const StockSchema = new mongoose.Schema( { userId: { type: mongoose.Schema.Types.ObjectId, refPath: "User", required: true, unique: true, }, products: [ProductRecordSchema], }, { timestamps: true, versionKey: false } ); export const PDStock = mongoose.model("PDStock", StockSchema);