/**
 * Knowledge probe: GROQ projection syntax.
 *
 * Tests deep knowledge of Sanity's query language without
 * providing any documentation context.
 *
 * See define-type-api.task.ts for detailed explanations of knowledge-probe properties.
 */
import { defineTask } from "@sanity/ailf-core"

export default defineTask({
  mode: "knowledge-probe",
  id: "kp-groq-projections",
  title: "Explain GROQ Projection Syntax",
  description:
    "Explain GROQ's projection syntax in detail, including: " +
    "object projections ({}), array projections, spread operator (...), " +
    "computed field names, the dereference operator (->), and " +
    "conditional projections using select().",
  area: "groq",
  difficulty: "intermediate",
  tags: ["knowledge-probe", "groq", "syntax"],
  // "depth-first" drills deep into one topic (vs "breadth-first" which covers many shallowly)
  probeStrategy: "depth-first",
  prompt: {
    text:
      "Explain GROQ's projection syntax in Sanity. Cover these topics:\n\n" +
      "1. Basic object projections with `{}`\n" +
      "2. Nested projections and the spread operator `...`\n" +
      "3. Computed field names\n" +
      "4. The dereference operator `->` for following references\n" +
      "5. Array slicing with `[0..5]` and `[0...5]`\n" +
      "6. Conditional projections using `select()`\n\n" +
      "Provide working code examples for each.",
  },
  assertions: [
    { type: "contains", value: "->" },
    { type: "contains", value: "select(" },
    // Templated rubrics so the compiled assertions carry `metadata.dimension`
    // and the scoring engine can populate per-dimension scores from the KP
    // profile (factual-correctness 0.45 / completeness 0.35 / currency 0.20).
    {
      type: "llm-rubric",
      template: "factual-correctness",
      criteria: [
        "The dereference operator `->` is correctly explained for following references",
        "The spread operator `...` is shown in a valid projection example",
        "`select()` is used with valid syntax for conditional projections",
        'Computed field names (e.g., `"label": title`) are demonstrated correctly',
        "Code examples use valid GROQ — no fabricated operators or deprecated syntax",
      ],
    },
    {
      type: "llm-rubric",
      template: "completeness",
      criteria: [
        "Basic object projection with `{}` is covered",
        "Nested projections and the spread operator are both addressed",
        "Computed/aliased field names are demonstrated",
        "The dereference operator `->` is included with a worked example",
        "Both inclusive (`[0..5]`) and exclusive (`[0...5]`) array slicing are explained",
        "Conditional projections via `select()` are covered",
      ],
    },
    {
      type: "llm-rubric",
      template: "currency",
      criteria: [
        "Examples reflect current GROQ syntax (post-2023) — no deprecated patterns",
        "Recommendations don't reference removed or legacy query forms",
        "Modern projection idioms are used (e.g., spread + override)",
      ],
    },
  ],
})
