import mongoose from 'mongoose'; // Define Product record schema const ProductRecordSchema = new mongoose.Schema({ SKU: { type: String, required: true, }, ProductName: { type: String, required: true, }, Sale: { type: Number, required: true, }, Inventory: { type: Number, required: true, }, }); // Define main Inventory schema const InventorySchema = new mongoose.Schema({ uniqueId: { type: String, required: true, unique: true, }, userId: { type: mongoose.Schema.Types.ObjectId, refPath: 'userType', required: true, }, userType: { type: String, required: true, enum: ['SalesCoOrdinator', 'TerritoryManager'], }, addedFor: { type: String, required: true, enum: ['PrincipalDistributor', 'RetailDistributor'], }, addedForId: { type: mongoose.Schema.Types.ObjectId, refPath: 'addedFor', required: true, }, products: [ProductRecordSchema], }, { timestamps: true, versionKey: false }); export const Inventory = mongoose.model('Inventory', InventorySchema);