i want to make configuration and schema in next.js

const mongoose = require("mongoose");

// User Schema
const UserSchema = new mongoose.Schema(
  {
    username: {
      type: String,
      required: [true, "Please provide a username"],
      trim: true,
      index: true,
    },
    email: {
      type: String,
      required: [true, "Please provide an email"],
      unique: true,
      lowercase: true,
      trim: true,
    },
    password: {
      type: String,
      required: [true, "Please provide a password"],
      minlength: 6,
      select: false,
    },
    role: {
      type: String,
      enum: ["Admin", "User", "Company"],
      default: "User",
    },
    image: String,
    badges: [
      {
        type: mongoose.Schema.Types.ObjectId,
        ref: "Badge",
      },
    ],
  },
  { timestamps: true }
);

// Article Schema
const ArticleSchema = new mongoose.Schema(
  {
    title: {
      type: String,
      required: true,
      trim: true,
      index: true,
    },
    description: {
      type: String,
      required: true,
    },
    category: {
      type: String,
      required: true,
      index: true,
    },
    media: {
      photos: [String],
      videos: [String],
    },
    isDeleted: {
      type: Boolean,
      default: false,
      index: true,
    },
  },
  { timestamps: true }
);

// UserChallenges Schema
const UserChallengesSchema = new mongoose.Schema(
  {
    userId: {
      type: mongoose.Schema.Types.ObjectId,
      required: true,
      ref: "User",
      index: true,
    },
    challengeId: {
      type: mongoose.Schema.Types.ObjectId,
      required: true,
      ref: "Challenges",
      index: true,
    },
    isDeleted: {
      type: Boolean,
      default: false,
      index: true,
    },
    progress: {
      type: Number,
      default: 0,
      min: 0,
    },
    completed: {
      type: Boolean,
      default: false,
    },
    image: [String],
    isApproved: {
      type: Boolean,
      default: false,
    },
  },

  { timestamps: true }
);

// Badges Schema
const BadgesSchema = new mongoose.Schema(
  {
    badge_name: {
      type: String,
      required: [true, "Badge name is required"],
      trim: true,
      index: true,
    },
    description: String,
    image: String,
  },
  { timestamps: true }
);

// Challenges Schema
const ChallengesSchema = new mongoose.Schema(
  {
    title: {
      type: String,
      required: [true, "Challenge title is required"],
      trim: true,
      index: true,
    },
    description: {
      type: String,
      required: [true, "Challenge description is required"],
    },
    targetValue: {
      type: Number,
      required: true,
      min: 0,
    },
    discount: {
      amount: {
        type: Number,
        required: true,
      },
      discountCode: {
        type: String,
        required: true,
      },
    },
    difficultyLevel: {
      type: String,
      enum: ["beginner", "intermediate", "advanced"],
      default: "intermediate",
    },
    participationCount: {
      type: Number,
      required: true,
      min: 0, // every participation will decrease this count
    },
    stages: [
      {
        stageNumber: {
          type: Number,
          required: true,
        },
        stageDescription: {
          type: String,
          required: true,
        },
        imageUrl: String,
      },
    ],
    image: String,
    isDeleted: {
      type: Boolean,
      default: false,
      index: true,
    },
  },
  { timestamps: true }
);

const productSchema = new mongoose.Schema({
  name: { type: String, required: true },
  description: { type: String, required: true },
  price: { type: Number, required: true },
  category: { type: String, required: true },
  images: [{ type: String }],
  isDeleted: { type: Boolean, default: false },
  stock_quantity: {
    type: Number,
    default: 0, // Default stock quantity
    min: 0, // Ensuring stock cannot be negative
  }
});


const CompanySchema = new mongoose.Schema(
  {
    user_id: {
      type: mongoose.Schema.Types.ObjectId, // Use ObjectId to reference the User table
      ref: "User", // Reference to the User model
      required: true,
    },
    company_name: {
      type: String,
      required: [true, "Company name is required"],
    },
    address: {
      type: String,
      required: [true, "Company address is required"],
    },
    contact_number: {
      type: String,
      required: [true, "Contact number is required"],
    },
    email: {
      type: String,
      required: [true, "Email is required"],
      unique: true,
    },
    website: {
      type: String,
      required: false,
    },
    createdAt: {
      type: Date,
      default: Date.now,
    },
    updatedAt: {
      type: Date,
      default: Date.now,
    },
  },
  { timestamps: true }
);


// Export models
module.exports = {
  User: mongoose.model("User", UserSchema),
  Article: mongoose.model("Article", ArticleSchema),
  UserChallenges: mongoose.model("UserChallenges", UserChallengesSchema),
  Badge: mongoose.model("Badge", BadgesSchema),
  Challenges: mongoose.model("Challenges", ChallengesSchema),
  Product:  mongoose.model("Product", productSchema),
  Company: mongoose.model("Company", CompanySchema),
};