const mongoose = require("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"]
    },
    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: ["Stock In", "Stock Out"]
    }
  },
  { timestamps: true }
);

module.exports = mongoose.model("StockTransaction", stockTransactionSchema);
