const mongoose = require("mongoose");

// Define sub-schemas first
const authorSchema = new mongoose.Schema(
  {
    name: String,
    type: String,
  },
  { _id: false },
);

const clientReviewSchema = new mongoose.Schema(
  {
    id: String,
    rating: Number,
    content: String,
    author: authorSchema,
    icon: String,
  },
  { _id: false },
);

const featureSchema = new mongoose.Schema(
  {
    title: String,
    description: String,
  },
  { _id: false },
);

const faqSchema = new mongoose.Schema(
  {
    id: String,
    question: String,
    answer: String,
    isExpanded: { type: Boolean, default: false },
  },
  { _id: false },
);

const serviceDetailsSchema = new mongoose.Schema(
  {
    title: String,
    description: String,
    mainImage: String,
    overviewTitle: String,
    overviewDescription: String,
    additionalDescription: String,
    keyFeaturesTitle: String,
    keyFeaturesImage: String,
    features: [featureSchema],
    faqTitle: String,
    faqImage: String,
    faq: [faqSchema],
  },
  { _id: false },
);

// Main service page schema
const serviceSchema = new mongoose.Schema(
  {
    pageTitle: String,

    // Main services section
    services: {
      title: {
        subTitle: String,
        mainTitle: String,
      },
      items: [
        {
          slug: String,
          name: String,
          description: String,
          image: String,
          layout: String,
          details: serviceDetailsSchema,
        },
      ],
    },

    // Destination countries section
    destinations: {
      backgroundImage: String,
      title: {
        subTitle: String,
        mainTitle: String,
      },
    },

    // Visa types section
    visas: {
      items: [
        {
          id: String,
          number: String,
          name: String,
          description: String,
          buttonText: String,
          buttonLink: String,
        },
      ],
    },

    // Client reviews section
    reviews: {
      title: {
        subTitle: String,
        mainTitle: String,
      },
      thumb: String,
      items: [clientReviewSchema],
    },
  },
  { timestamps: true },
);

module.exports = mongoose.model("Service", serviceSchema);
