import mongoose from 'mongoose';

const stockTransactionSchema = new mongoose.Schema(
  {
    product: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'Product',
      required: [true, 'Product is required'],
    },
    warehouse: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'Warehouse',
      required: [true, 'Warehouse is required'],
    },
    transactionDate: {
      type: Date,
      required: [true, 'Transaction date is required'],
      default: Date.now,
    },
    quantityMoved: {
      type: Number,
      required: [true, 'Quantity moved is required'],
      min: [1, 'Quantity moved must be at least 1'],
    },
    transactionType: {
      type: String,
      required: [true, 'Transaction type is required'],
      enum: {
        values: ['Stock In', 'Stock Out'],
        message: 'Transaction type must be either "Stock In" or "Stock Out"',
      },
    },
  },
  {
    timestamps: true,
  }
);

const StockTransaction = mongoose.model('StockTransaction', stockTransactionSchema);

export default StockTransaction;
