import mongoose from 'mongoose';

// Define Product record schema
const ProductRecordSchema = new mongoose.Schema({
  productid: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Product',
    required: true,
  },
  Stock: {
    type: Number,
    default: 0,
  },
});

// Define main Stock schema
const StockSchema = new mongoose.Schema({
  userId: {
    type: mongoose.Schema.Types.ObjectId,
    refPath: 'User',
    required: true,
  },
  products: [ProductRecordSchema],
}, { timestamps: true, versionKey: false });

export const PDStock = mongoose.model('PDStock', StockSchema);
