import mongoose from 'mongoose';

const purchaseSchema = new mongoose.Schema(
  {
    product: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'Product',
      required: [true, 'Product is required'],
    },
    supplier: {
      type: String,
      trim: true,
      default: '',
    },
    purchaseDate: {
      type: Date,
      default: Date.now,
    },
    quantity: {
      type: Number,
      required: [true, 'Quantity is required'],
      min: [1, 'Quantity must be at least 1'],
    },
    size: {
      type: String,
      default: '',
      trim: true,
    },
    variant: {
      type: String,
      default: '',
      trim: true,
    },
    variantLabel: {
      type: String,
      default: '',
      trim: true,
    },
    sellingUnit: {
      type: String,
      default: 'pcs',
      trim: true,
    },
    purchasePrice: {
      type: Number,
      required: [true, 'Purchase price is required'],
      min: [0, 'Purchase price cannot be negative'],
    },
    totalAmount: {
      type: Number,
      required: [true, 'Total amount is required'],
    },
  },
  { timestamps: true }
);

export default mongoose.model('Purchase', purchaseSchema);
