const mongoose = require("mongoose");

// Clear cache
if (mongoose.models.Booking) {
  delete mongoose.models.Booking;
}
if (mongoose.connection.models.Booking) {
  delete mongoose.connection.models.Booking;
}

const bookingSchema = new mongoose.Schema(
  {
    hero: {
      title: String,
      backgroundImage: String,
    },

    searchBar: {
      locationLabel: String,
      holidaySeasonLabel: String,
      searchButtonText: String,
    },

    filterPanel: {
      title: String,
      priceTitle: String,
      priceLabel: String,
      pricePlaceholder: String,
      priceMin: Number,
      priceMax: Number,
      activitiesTitle: String,
      ageTitle: String,
      ageSelectPlaceholder: String,
      ageMin: Number,
      ageMax: Number,
      ratingTitle: String,
      ratingOptions: [
        {
          value: String,
          label: String,
        },
      ],
      resetButtonText: String,
    },

    programs: [
      {
        value: String,
        label: String,
      },
    ],

    holidays: [
      {
        value: String,
        label: String,
      },
    ],

    locations: [
      {
        value: String,
        label: String,
      },
    ],

    camps: [
      {
        name: String,
        price: Number,
        priceText: String,
        season: [String],
        age: [Number],
        locations: [String],
        image: String,
        link: String,
        program: String,
        rating: Number,
      },
    ],
    
    // Configuration - Dùng Mixed type để chấp nhận bất kỳ structure nào
    configuration: mongoose.Schema.Types.Mixed,

    formSteps: [
      {
        step: Number,
        title: String,
        sections: [
          {
            id: String,
            fields: [mongoose.Schema.Types.Mixed],
          },
        ],
      },
    ],

    validation: mongoose.Schema.Types.Mixed,
  },
  { 
    timestamps: true,
    strict: false 
  }
);

module.exports = mongoose.model("Booking", bookingSchema);