type TestimonialNode = {
  title: string;
  content: string;
  featuredImage?: {
    node?: {
      sourceUrl: string;
      altText?: string | null;
    };
  } | null;
  testimonialFields?: {
    designation?: string | null;
  } | null;
};

export async function getTestimonials(): Promise<TestimonialNode[]> {
  const res = await fetch(process.env.NEXT_PUBLIC_WP_GRAPHQL_URL!, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      query: `
        query Testimonials {
          testimonials {
            nodes {
              title
              content
              featuredImage {
                node {
                  sourceUrl
                  altText
                }
              }
              testimonialFields {
                designation
              }
            }
          }
        }
      `,
    }),
    next: { revalidate: 60 }, // ISR
  });

  const json = await res.json();
  return json?.data?.testimonials?.nodes ?? [];
}
