const mongoose = require("mongoose"); const BadgeSchema = new mongoose.Schema( { name: { type: String, required: true, unique: true, }, description: { type: String, required: true, }, icon: { type: String, required: true, }, criteria: { type: { type: String, enum: [ "street_adoptions", "task_completions", "post_creations", "event_participations", "points_earned", "consecutive_days", "special", ], required: true, }, threshold: { type: Number, required: true, }, }, rarity: { type: String, enum: ["common", "rare", "epic", "legendary"], default: "common", }, order: { type: Number, default: 0, }, }, { timestamps: true, }, ); // Index for efficient badge queries BadgeSchema.index({ "criteria.type": 1, "criteria.threshold": 1 }); BadgeSchema.index({ rarity: 1 }); BadgeSchema.index({ order: 1 }); module.exports = mongoose.model("Badge", BadgeSchema);