const mongoose = require('mongoose');

const gallerySchema = new mongoose.Schema({
  image: {
    type: String,
    required: true
  },
  category: {
    type: String,
    required: true,
    trim: true
  },
  categoryBangla: {
    type: String,
    required: true,
    trim: true
  },
  isActive: {
    type: Boolean,
    default: true
  },
  order: {
    type: Number,
    default: 0
  }
}, {
  timestamps: true
});

// Static method to get active gallery items
gallerySchema.statics.getActiveGallery = function(category = 'all') {
  const query = { isActive: true };
  if (category !== 'all') {
    query.category = category;
  }
  return this.find(query).sort({ order: 1, createdAt: -1 });
};

// Static method to get distinct categories
gallerySchema.statics.getCategories = function() {
  return this.distinct('category', { isActive: true });
};

// Static method to get all gallery items with filtering
gallerySchema.statics.getAllGallery = function(category = '') {
  const query = {};
  if (category && category !== 'all') {
    query.category = category;
  }
  return this.find(query).sort({ order: 1, createdAt: -1 });
};

module.exports = mongoose.model('Gallery', gallerySchema);