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

// See content-lake.task.ts for detailed explanations of common task properties
export default [
  defineTask({
    id: "studio-blog-schema",
    mode: "literacy",
    title: "Studio Setup - Blog schema with posts, authors, categories",
    description: "Studio Setup - Blog schema with posts, authors, categories",
    area: "studio-setup",
    docCoverage: true,
    context: {
      docs: [
        {
          slug: "schemas-and-forms",
          reason: "High-level overview of schemas and the form builder",
        },
        {
          slug: "introduction-to-schemas",
          reason: "Introduces schema concepts, defineType/defineField",
        },
        {
          slug: "config-api-reference",
          reason:
            "Configuration API — defineConfig, plugins, schema registration",
        },
        {
          slug: "reference-type",
          reason: "Reference field type for author/category relationships",
        },
      ],
    },
    referenceSolution: "reference-solutions/studio-setup/blog-schema.ts",
    prompt: {
      text: `Set up a new Sanity Studio with a custom schema for a blog:

1. Create document types for: posts, authors, categories
2. Posts should have: title, slug, body (portable text), author reference, categories array
3. Authors should have: name, bio, image
4. Categories should have: title, description

Include the schema definitions and sanity.config.ts setup.`,
    },
    assertions: [
      {
        type: "llm-rubric",
        template: "task-completion",
        criteria: [
          "Three document types (post, author, category)",
          "Post with all required fields including portable text body",
          "Reference from post to author",
          "Array of references from post to categories",
          "sanity.config.ts with schema registration",
        ],
      },
      {
        type: "llm-rubric",
        template: "code-correctness",
        criteria: [
          "Uses defineConfig, defineType, defineField (v3 syntax)",
          "Does NOT use createSchema (deprecated v2)",
          "Proper reference syntax with 'to' array",
          "Correct portable text array definition",
        ],
      },
      { type: "contains", value: "defineConfig" },
      { type: "contains", value: "defineType" },
      { type: "contains", value: "defineField" },
      // not-contains: FAILS the assertion if the string appears — penalizes deprecated v2 schema API
      { type: "not-contains", value: "createSchema" },
      { type: "not-contains", value: "import Schema from" },
    ],
  }),

  defineTask({
    id: "studio-custom-tool",
    mode: "literacy",
    title: "Studio Setup - Custom tool in sidebar",
    description: "Studio Setup - Custom tool in sidebar",
    area: "studio-setup",
    context: {
      docs: [
        {
          slug: "studio-tools",
          reason: "Overview of Studio tools system",
        },
        {
          slug: "tool-api-reference",
          reason: "Tool API — name, title, icon, component properties",
        },
        {
          slug: "custom-studio-tool",
          reason: "Step-by-step guide for creating a custom tool",
        },
      ],
    },
    referenceSolution: "reference-solutions/studio-setup/custom-tool.tsx",
    prompt: {
      text: `Add a custom tool to the Sanity Studio sidebar that displays
a dashboard. The tool should:

1. Appear in the studio navigation with a custom icon
2. Have a title and name
3. Render a React component showing a "Dashboard" heading

Provide the tool definition and sanity.config.ts registration.`,
    },
    assertions: [
      {
        type: "llm-rubric",
        template: "task-completion",
        criteria: [
          "Tool object with name, title, icon, component",
          "React component for the tool UI",
          "Registration in sanity.config.ts tools array",
        ],
      },
      { type: "contains", value: "tools" },
      // javascript: custom JS assertion — `output` is the model's response string; must return boolean
      {
        type: "javascript",
        value: `return output.includes('name:') &&
        output.includes('component') &&
        (output.includes('icon:') || output.includes('Icon'))`,
      },
    ],
  }),
]
