/**
 * sanity-literacy preset — Sanity-specific domain configuration for literacy evaluation.
 *
 * This is a domain preset that targets the `literacy` mode base. It provides
 * Sanity-specific configuration:
 * - Sanity doc source definitions (production, branch, local)
 * - Product feature registry for coverage auditing
 * - DocFetcher factory (SanityDocFetcher)
 * - Sanity fixture resolver (sanity:// scheme)
 *
 * Evaluation methodology (rubrics, scoring, prompts) is inherited from the
 * `literacy` mode base — see mode-bases/literacy.ts.
 *
 * @see docs/archive/exec-plans/architecture-overhaul/phase-8-scoring-storage-presets.md
 */
import { env } from "../../../_vendor/ailf-core/index.js";
import { SanityDocFetcher } from "../../../adapters/doc-fetchers/index.js";
// ---------------------------------------------------------------------------
// Factory
// ---------------------------------------------------------------------------
/**
 * Create the sanity-literacy preset with all Sanity-specific configuration.
 *
 * The `rootDir` option controls where the SanityDocFetcher resolves file
 * paths. When omitted it defaults to `process.cwd()`, which matches the
 * composition root's existing behavior.
 */
export function createSanityLiteracyPreset(options) {
    const rootDir = options?.rootDir ?? process.cwd();
    return {
        name: "sanity-literacy",
        manifest: {
            name: "sanity-literacy",
            version: "1.0.0",
            description: "Documentation literacy evaluation for Sanity.io — measures how " +
                "effectively documentation enables AI coding tools to implement " +
                "features correctly.",
            pluginApiVersion: 1,
        },
        // ── Mode ──────────────────────────────────────────────────
        // Targets the literacy mode base. Evaluation methodology (rubrics,
        // scoring, prompts) is inherited from mode-bases/literacy.ts.
        mode: "literacy",
        // ── Fixture resolvers ────────────────────────────────────
        fixtureResolvers: [
            {
                scheme: "sanity://",
                handlerModule: "./fixture-resolver.js",
            },
        ],
        // ── Doc fetcher factory ──────────────────────────────────
        // Closure captures rootDir so the registry can instantiate
        // the fetcher without knowing about Sanity internals.
        docFetcher: () => new SanityDocFetcher(rootDir),
        // ── Source definitions ────────────────────────────────────
        // Mirrors config/sources.ts — env() calls are evaluated at
        // preset creation time, matching the existing runtime behavior.
        sourceDefs: [
            {
                name: "production",
                baseUrl: "https://www.sanity.io/docs",
                projectId: env("SANITY_PROJECT_ID", "3do82whm"),
                dataset: env("SANITY_DATASET", "next"),
            },
            {
                name: "branch",
                baseUrl: env("DOC_BASE_URL", ""),
                projectId: env("SANITY_PROJECT_ID", "3do82whm"),
                dataset: env("SANITY_DATASET", "next"),
            },
            {
                name: "local",
                baseUrl: `http://localhost:${env("DOC_LOCAL_PORT", "3001")}/docs`,
                projectId: env("SANITY_PROJECT_ID", "3do82whm"),
                dataset: env("SANITY_DATASET", "next"),
            },
        ],
        // ── Feature registry ─────────────────────────────────────
        // Complete product feature set for coverage auditing.
        featureDefs: {
            features: [
                // Currently covered (have evaluation tasks)
                {
                    id: "groq",
                    name: "GROQ Query Language",
                    sections: ["content-lake"],
                    status: "covered",
                    area: "groq",
                    priority: "critical",
                },
                {
                    id: "visual-editing",
                    name: "Visual Editing",
                    sections: ["visual-editing"],
                    status: "covered",
                    area: "visual-editing",
                    priority: "critical",
                },
                {
                    id: "nextjs-live",
                    name: "Next.js Live Preview",
                    sections: ["visual-editing"],
                    status: "covered",
                    area: "nextjs-live",
                    priority: "high",
                },
                {
                    id: "functions",
                    name: "Sanity Functions",
                    sections: ["compute-and-ai"],
                    status: "covered",
                    area: "functions",
                    priority: "high",
                },
                {
                    id: "studio-setup",
                    name: "Studio Configuration",
                    sections: ["studio"],
                    status: "covered",
                    area: "studio-setup",
                    priority: "high",
                },
                {
                    id: "frameworks",
                    name: "Framework Integration",
                    sections: ["developer-guides"],
                    status: "covered",
                    area: "frameworks",
                    priority: "high",
                },
                // Uncovered (no evaluation tasks yet)
                {
                    id: "portable-text",
                    name: "Portable Text",
                    sections: ["content-lake", "studio"],
                    status: "uncovered",
                    priority: "high",
                },
                {
                    id: "image-assets",
                    name: "Image & Asset Handling",
                    sections: ["content-lake", "apis-and-sdks"],
                    status: "uncovered",
                    priority: "high",
                },
                {
                    id: "mutations",
                    name: "Mutations & Transactions",
                    sections: ["content-lake", "apis-and-sdks"],
                    status: "uncovered",
                    priority: "high",
                },
                {
                    id: "schemas",
                    name: "Schema Types & Validation",
                    sections: ["studio", "content-lake"],
                    status: "uncovered",
                    priority: "medium",
                },
                {
                    id: "authentication",
                    name: "Authentication & Access Control",
                    sections: ["apis-and-sdks"],
                    status: "uncovered",
                    priority: "medium",
                },
                {
                    id: "webhooks",
                    name: "Webhooks",
                    sections: ["content-lake"],
                    status: "uncovered",
                    priority: "medium",
                },
                {
                    id: "realtime",
                    name: "Real-time Listeners",
                    sections: ["apis-and-sdks"],
                    status: "uncovered",
                    priority: "low",
                },
                {
                    id: "ai-assist",
                    name: "AI Assist",
                    sections: ["compute-and-ai", "studio"],
                    status: "uncovered",
                    priority: "medium",
                },
            ],
        },
    };
}
// ---------------------------------------------------------------------------
// Convenience constant — preset with default options for backward compat
// ---------------------------------------------------------------------------
/**
 * Pre-built preset instance using default options (cwd for rootDir).
 *
 * Prefer `createSanityLiteracyPreset()` when you need to control rootDir
 * or other options. This constant exists for backward compatibility with
 * code that imports `sanityLiteracyPreset` directly.
 */
export const sanityLiteracyPreset = createSanityLiteracyPreset();
/**
 * Register the sanity-literacy preset in a plugin registry.
 */
export function registerSanityLiteracyPreset(registry) {
    registry.registerPreset(sanityLiteracyPreset);
}
