import mongoose from 'mongoose'; import { generateId } from '../../utils.js'; const { Schema } = mongoose; // Define the main product SKU schema const productSkuSchema = new Schema( { _reference: { type: String, default: () => generateId()() }, sku: { type: String, required: true }, product: { type: Schema.Types.ObjectId, ref: 'product', required: true }, name: { type: String, required: true }, description: { type: String, required: false }, }, { timestamps: true } ); // Add virtual id getter productSkuSchema.virtual('id').get(function () { return this._id; }); // Configure JSON serialization to include virtuals productSkuSchema.set('toJSON', { virtuals: true }); // Create and export the model export const productSkuModel = mongoose.model('productSku', productSkuSchema);