var mongoose = require("mongoose");

var deliverySchema = new mongoose.Schema(
  {
    shipment: {
      type: mongoose.Schema.Types.ObjectId,
      ref: "Shipment",
      required: [true, "Shipment is required"],
    },
    deliveryCode: {
      type: String,
      required: [true, "Delivery code is required"],
      unique: true,
      trim: true,
    },
    deliveryDate: {
      type: Date,
      required: [true, "Delivery date is required"],
    },
    quantityDelivered: {
      type: Number,
      required: [true, "Quantity delivered is required"],
      min: [1, "Quantity must be greater than zero"],
    },
    deliveryStatus: {
      type: String,
      required: [true, "Delivery status is required"],
      enum: ["Pending", "Partial", "Completed", "Returned"],
    },
  },
  { timestamps: true }
);

module.exports = mongoose.model("Delivery", deliverySchema);
