import mongoose from 'mongoose';

const shipmentSchema = new mongoose.Schema(
  {
    // order reference
    order_id: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'Order',
      required: true,
    },

    // Shiprocket response data
    shiprocket_order_id: { type: String },
    shiprocket_shipment_id: { type: String },
    awb_code: { type: String },
    courier_id: { type: Number },
    courier_name: { type: String },

    // Shipment status
    status: {
      type: String,
      enum: ['pending', 'booked', 'picked', 'in_transit', 'delivered', 'cancelled', 'returned'],
      default: 'pending',
    },

    // Customer delivery address
    delivery_address: {
      name: String,
      phone: String,
      address: String,
      city: String,
      state: String,
      pincode: String,
      country: { type: String, default: 'India' },
    },

    // Package details
    weight: { type: Number },
    dimensions: {
      length: Number,
      breadth: Number,
      height: Number,
    },

    // Tracking
    tracking_url: { type: String },
    estimated_delivery: { type: Date },

    // COD
    is_cod: { type: Boolean, default: false },
    cod_amount: { type: Number, default: 0 },
  },
  { timestamps: true }
);

export default mongoose.models.Shipment || mongoose.model('Shipment', shipmentSchema);