import type { NextApiRequest, NextApiResponse } from "next";

import { withRateLimit } from "@kan/api/utils/rateLimit";

export default withRateLimit(
  { points: 100, duration: 60 },
  async (req: NextApiRequest, res: NextApiResponse) => {
  if (req.method !== "GET") {
    return res.status(405).json({ message: "Method not allowed" });
  }

  try {
    const response = await fetch("https://formbricks.com/api/oss-friends");
    if (!response.ok) {
      throw new Error("Failed to fetch from Formbricks");
    }
    const data = await response.json();

    return res.status(200).json(data);
  } catch (error) {
    console.error("Error fetching OSS friends:", error);
    return res.status(500).json({ message: "Failed to fetch OSS friends" });
  }
  },
);
