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

// See content-lake.task.ts for detailed explanations of common task properties
export default [
  defineTask({
    id: "functions-webhook",
    mode: "literacy",
    title: "Functions - Webhook on document publish",
    description: "Functions - Webhook on document publish",
    area: "functions",
    docCoverage: true,
    context: {
      docs: [
        {
          slug: "functions-introduction",
          reason: "Functions overview — deployment, triggers, lifecycle",
        },
        {
          slug: "webhooks",
          reason: "GROQ-powered webhooks — configuration and filtering",
        },
        {
          slug: "function-wrapper",
          reason: "Function handler reference — event shape, exports",
        },
        {
          slug: "functions-cheatsheet",
          reason: "Quick reference for common function patterns",
        },
      ],
    },
    referenceSolution: "reference-solutions/functions/publish-webhook.ts",
    prompt: {
      text: `Deploy a Sanity function that triggers when a document is published
and sends a webhook notification to an external endpoint.

Requirements:
1. The function should trigger on document publish events
2. Filter to only fire for "post" document types
3. Send a POST request to an external URL with the document data
4. Handle errors gracefully

Provide a complete implementation including any configuration.`,
    },
    assertions: [
      {
        type: "llm-rubric",
        template: "task-completion",
        criteria: [
          "Event-driven function definition",
          "Document type filtering (post type only)",
          "HTTP webhook call with document payload",
          "Basic error handling",
        ],
      },
      {
        type: "llm-rubric",
        template: "code-correctness",
        criteria: [
          "No deprecated API patterns",
          "Proper error handling",
          "Idiomatic function handler structure",
        ],
      },
    ],
  }),
]
