const mongoose = require('mongoose');

const gpsSchema = new mongoose.Schema({
  vehicle_id: { type: mongoose.Schema.Types.ObjectId, ref: 'Vehicle', required: true },
  trip_id: { type: mongoose.Schema.Types.ObjectId, ref: 'Trip' },
  latitude: { type: Number, required: true },
  longitude: { type: Number, required: true },
  speed: { type: Number, default: 0 },
  heading: { type: Number, default: 0 },
  altitude: { type: Number, default: 0 },
  accuracy: { type: Number, default: 0 },
  recorded_at: { type: Date, default: Date.now },
}, { timestamps: false });

gpsSchema.index({ vehicle_id: 1, recorded_at: -1 });

module.exports = mongoose.model('GpsTracking', gpsSchema);
