const mongoose = require('mongoose');

const tripSchema = new mongoose.Schema({
  trip_code: { type: String, required: true, unique: true },
  vehicle_id: { type: mongoose.Schema.Types.ObjectId, ref: 'Vehicle', required: true },
  driver_id: { type: mongoose.Schema.Types.ObjectId, ref: 'Driver', required: true },
  customer_id: { type: mongoose.Schema.Types.ObjectId, ref: 'Customer' },
  origin: { type: String, required: true },
  destination: { type: String, required: true },
  distance_km: Number,
  scheduled_start: { type: Date, required: true },
  scheduled_end: Date,
  actual_start: Date,
  actual_end: Date,
  status: { type: String, enum: ['scheduled','in_progress','completed','cancelled'], default: 'scheduled' },
  cargo_description: String,
  cargo_weight: Number,
  notes: String,
  fuel_cost: { type: Number, default: 0 },
  total_cost: { type: Number, default: 0 },
}, { timestamps: true });

module.exports = mongoose.model('Trip', tripSchema);
