const mongoose = require('mongoose');

const TrackingSchema = new mongoose.Schema({
    userId: { type: String, required: true }, // Unique user identifier

    userId: {
       type: mongoose.Schema.Types.ObjectId,
        ref: 'User',  // Reference to user model
        required: true
      },
    deviceId: { type: String, required: false }, // Unique device ID
    trackingSessionId: { type: String, required: true }, // Unique tracking session
    locations: [
        {
            latitude: { type: Number, required: true },
            longitude: { type: Number, required: true },
            timestamp: { type: Date, default: Date.now } // Stores time of tracking
        }
    ]
}, { timestamps: true });

module.exports = mongoose.model('Tracking', TrackingSchema);
