import { defineTask } from "../../_vendor/ailf-core/index.js"

// See content-lake.task.ts for detailed explanations of common task properties
export default [
  defineTask({
    id: "nextjs-app-router-integration",
    mode: "literacy",
    title: "Next.js - App Router integration with TypeScript",
    description: "Next.js - App Router integration with TypeScript",
    area: "nextjs-live",
    docCoverage: true,
    context: {
      docs: [
        {
          slug: "next-js-app-router-quickstart",
          reason: "Primary Next.js App Router quickstart guide",
        },
        {
          slug: "diplaying-content-in-next-js",
          reason: "Fetching and displaying Sanity content in Next.js",
        },
        {
          slug: "sanity-typegen",
          reason: "TypeGen — generating TypeScript types from GROQ queries",
        },
        {
          slug: "groq-introduction",
          reason: "GROQ query language introduction",
        },
      ],
    },
    referenceSolution: "reference-solutions/nextjs/app-router-integration.tsx",
    prompt: {
      text: `Integrate Sanity into a Next.js 16 App Router application
with full TypeScript support:

1. Set up the Sanity client with proper configuration
2. Create a typed GROQ query for fetching blog posts
3. Build a server component that fetches and renders posts
4. Generate TypeScript types using sanity typegen

Provide all files needed for a working integration.`,
    },
    assertions: [
      {
        type: "llm-rubric",
        template: "task-completion",
        criteria: [
          "Sanity client configuration (createClient)",
          "GROQ query with proper syntax",
          "Next.js App Router server component using async/await",
          "TypeScript type definitions or typegen setup",
        ],
      },
      {
        type: "llm-rubric",
        template: "code-correctness",
        criteria: [
          "Uses @sanity/client (not deprecated packages)",
          "App Router patterns (not Pages Router)",
          "Proper server component data fetching (no useEffect)",
          "Valid GROQ query syntax",
        ],
      },
      { type: "contains", value: "createClient" },
      {
        type: "contains-any",
        value: ["groq", "GROQ", "*["],
      },
    ],
  }),
]
