import mongoose, { Document, Schema } from 'mongoose';

export interface IProductSize extends Document {
  product: mongoose.Types.ObjectId;
  color: mongoose.Types.ObjectId;
  size: mongoose.Types.ObjectId;
  sku: string;
  price: number;
  comparePrice?: number;
  inventory: number;
  isActive: boolean;
  createdAt: Date;
  updatedAt: Date;
}

const ProductSizeSchema: Schema = new Schema({
  product: {
    type: Schema.Types.ObjectId,
    ref: 'Product',
    required: [true, 'Product is required']
  },

  size: {
    type: Schema.Types.ObjectId,
    ref: 'Size',
    required: [true, 'Size is required']
  },

}, {
  timestamps: true
});

// Indexes for better performance
ProductSizeSchema.index({ product: 1, size: 1 }, { unique: true });
ProductSizeSchema.index({ product: 1 });
ProductSizeSchema.index({ size: 1 });

export default mongoose.models.ProductSize || mongoose.model('ProductSize', ProductSizeSchema);
