/**
 * createCanvasLiteracyPreset — Canvas-specific literacy preset.
 *
 * Plugs a `CanvasDocFetcher` into the literacy mode base. The `source`
 * parameter is narrowed by `PresetFactory<"sanity-canvas">` in
 * `PRESET_FACTORY_BY_SOURCE`, so no in-preset type-asserting is needed.
 *
 * The bearer token is resolved eagerly at preset-construction time —
 * a missing token fails fast here rather than at first fetch.
 */
import { loadCanvasToken } from "./auth.js";
import { createCanvasHttpClient } from "./canvas-client.js";
import { CanvasDocFetcher } from "./doc-fetcher.js";
import { canvasApiBase } from "./hosts.js";
export function createCanvasLiteracyPreset({ rootDir, source, }) {
    // Eagerly resolve the token so a missing env var is a preset-construction
    // error, not a runtime failure on the first fetch.
    const token = loadCanvasToken(source);
    const client = createCanvasHttpClient(canvasApiBase(source), token);
    return {
        name: "canvas-literacy",
        manifest: {
            name: "canvas-literacy",
            version: "1.0.0",
            description: "Documentation literacy evaluation backed by Sanity Canvas — " +
                "fetches documents as markdown from the Canvas CRUD REST API.",
            pluginApiVersion: 1,
        },
        mode: "literacy",
        // Like the Drive preset, no fixtureResolvers / featureDefs — those
        // surfaces exist for Sanity-specific content-lake semantics and don't
        // have a Canvas analogue today.
        docFetcher: () => new CanvasDocFetcher(source, client, { rootDir }),
    };
}
