import mongoose from 'mongoose';

const stockHistorySchema = new mongoose.Schema({
  product: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Product',
    required: [true, 'Product is required'],
    index: true,
  },
  type: {
    type: String,
    required: [true, 'Type is required'],
    enum: ['PURCHASE', 'SALE', 'ADJUSTMENT', 'RETURN'],
  },
  quantity: {
    type: Number,
    required: [true, 'Quantity is required'],
  },
  previousStock: {
    type: Number,
    required: [true, 'Previous stock is required'],
  },
  newStock: {
    type: Number,
    required: [true, 'New stock is required'],
  },
  size: {
    type: String,
    default: null,
  },
  variant: {
    type: String,
    default: '',
  },
  variantLabel: {
    type: String,
    default: '',
  },
  productName: {
    type: String,
    default: '',
  },
  sellingUnit: {
    type: String,
    default: 'pcs',
  },
  reference: {
    type: String,
    default: '',
  },
  date: {
    type: Date,
    default: Date.now,
  },
});

export default mongoose.model('StockHistory', stockHistorySchema);
