const mongoose = require('mongoose');

const HeaderMenuSchema = new mongoose.Schema({
  title: {
    type: String,
    required: true,
    trim: true
  },
  slug: {
    type: String,
    required: true,
    trim: true,
    lowercase: true
  },
  url: {
    type: String,
    required: true,
    trim: true
  },
  parentId: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'HeaderMenu',
    default: null
  },
  order: {
    type: Number,
    default: 0
  },
  status: {
    type: String,
    enum: ['active', 'inactive'],
    default: 'active'
  },
  type: {
    type: String,
    enum: ['internal', 'external'],
    default: 'internal'
  }
}, {
  timestamps: true
});

// Indexes for optimization
HeaderMenuSchema.index({ order: 1 });
HeaderMenuSchema.index({ status: 1 });
HeaderMenuSchema.index({ parentId: 1, order: 1 }); // Useful for fetching children in order

module.exports = mongoose.model('HeaderMenu', HeaderMenuSchema);
