const mongoose = require('mongoose');

const sceneSchema = new mongoose.Schema({
    tourId: { 
        type: mongoose.Schema.Types.ObjectId, 
        ref: 'Tour',
        required: true
    },
    name: { 
        type: String, 
        required: true,
        trim: true 
    },
    description: {
        type: String,
        trim: true
    },
    assetId: { 
        type: mongoose.Schema.Types.ObjectId, 
        ref: 'Asset',
        required: true
    },
    scene_url: String,
    gps: {
        lat: Number,
        lng: Number
    },
    createdBy: { 
        type: mongoose.Schema.Types.ObjectId, 
        ref: 'User', 
        required: true 
    },
    uploadedAt: { 
        type: Date, 
        default: Date.now 
    },
    status: {
        type: String,
        enum: ['processing', 'completed', 'failed'],
        default: 'processing'
    },
    privacy: {
        type: String,
        enum: ['public', 'private', 'member', 'shared'],
        default: 'private'
    },
    shareToken: String,
    shareTokenExpires: Date,
    sharedWith: [{ 
        type: mongoose.Schema.Types.ObjectId, 
        ref: 'User' 
    }],
    sharedEmails: [String],
    views: { 
        type: Number, 
        default: 0 
    },
    viewHistory: [{
        date: Date,
        count: Number
    }]
}, { 
    timestamps: true 
});

module.exports = mongoose.model('Scene', sceneSchema);