const mongoose = require('mongoose'); const Schema = mongoose.Schema; const FoundryLinkRequestSchema = new Schema({ codeHash: { type: String, required: true, unique: true }, // Kept in clear text so the campaign settings screen can re-display a pending // pairing code after a reload or a backend restart. It is only ever returned // to the user who created the request and is cleared once the link completes. code: { type: String }, source: { type: String, enum: ['dragonroll'], required: true }, campaign: { type: Schema.Types.ObjectId, ref: 'Campaign' }, createdBy: { type: Schema.Types.ObjectId, ref: 'User' }, worldId: { type: String }, worldTitle: { type: String }, system: { type: String }, foundryUrl: { type: String }, createdAt: { type: Date, default: Date.now }, expiresAt: { type: Date, required: true }, completedAt: { type: Date } }); FoundryLinkRequestSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 }); module.exports = mongoose.model('FoundryLinkRequest', FoundryLinkRequestSchema);