// Exercise 1: async Server Component data fetching
//
// Model app/page.tsx as a Server Component. Implement getPosts (a
// pretend DB call) and Page, an async function component that awaits
// it and returns the number of posts found and their titles joined
// with ", ".

interface Post {
  id: number;
  title: string;
}

async function getPosts(): Promise<Post[]> {
  // pretend DB round-trip
  return [
    { id: 1, title: "Hello World" },
    { id: 2, title: "Server Components 101" },
    { id: 3, title: "Streaming with Suspense" },
  ];
}

async function Page(): Promise<{ count: number; titles: string }> {
  // TODO: await getPosts(), then return { count: posts.length, titles: posts.map(p => p.title).join(", ") }
  return { count: 0, titles: "" };
}

// --- self-check: do not modify below this line ---
async function runCheck() {
  const result = await Page();
  const ok = result.count === 3 && result.titles === "Hello World, Server Components 101, Streaming with Suspense";
  console.log(ok ? "PASS" : `FAIL — got ${JSON.stringify(result)}`);
}

runCheck();
