const FAQ_QUERY = `
  query GetFaqs($id: Int!) {
    easyAccordionFaqsById(id: $id) {
      question
      answer
    }
  }
`;

export async function getFaqsByAccordionId(id: number) {
  const res = await fetch(process.env.NEXT_PUBLIC_WP_GRAPHQL_URL!, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      query: FAQ_QUERY,
      variables: { id },
    }),
    // ISR – cache for performance
    next: { revalidate: 3600 },
  });

  if (!res.ok) {
    throw new Error("Failed to fetch FAQs");
  }

  const json = await res.json();
  return json.data.easyAccordionFaqsById;
}
