// https://studio-api.prod.suno.com/api/search/

import { NextRequest } from "next/server";

export async function GET(request: NextRequest) {
  const query = request.nextUrl.searchParams.get("query") || "cello";

  const res = await fetch("https://studio-api.prod.suno.com/api/search/", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      search_queries: [
        {
          name: "tag_song",
          search_type: "tag_song",
          term: query,
          from_index: 0,
          rank_by: "most_relevant",
        },
      ],
    }),
    next: {
      revalidate: 60,
    },
  });
  const data = await res.json();

  return Response.json({ data });
}
