/**
 * Google Drive adapter — config schema + eager-validating helper (W0207).
 *
 * `defineGoogleDriveSource` is the user-facing entry point for declaring a
 * Drive source in `config/sources.ts`. It parses the input through Zod
 * eagerly so typos / wrong shapes surface at config-load time, not at
 * first eval-run. Defaults for `kind`, `recurseDepth`, and `maxFiles` are
 * applied at parse time.
 */
import { z } from "zod";
import { DRIVE_ID_PATTERN } from "./ids.js";
/**
 * Zod schema for a Drive source. Asserts `satisfies z.ZodType<GoogleDriveSource>`
 * against the independently-authored interface in `types.ts` (D0045 trust-
 * boundary rule) — drift becomes a compile error.
 */
export const GoogleDriveSourceSchema = z.object({
    kind: z.literal("google-drive").default("google-drive"),
    name: z.string().min(1, "name is required"),
    // Drive ids are alphanumeric + `_-`; the regex also guards the query-
    // interpolation seam in `doc-fetcher.ts` (`q: "'<id>' in parents…"`)
    // against single-quote escapes (I1).
    rootFolderId: z
        .string()
        .regex(DRIVE_ID_PATTERN, "rootFolderId must match /^[A-Za-z0-9_-]+$/"),
    recurseDepth: z.number().int().min(0).default(3),
    maxFiles: z.number().int().min(1).default(2000),
    mimeFilters: z.array(z.string()).optional(),
    default: z.boolean().optional(),
});
/**
 * Define a Google Drive doc source for `config/sources.ts`. Validates
 * eagerly; throws a `ZodError` describing the offending field on bad
 * input. The returned value is fully populated with defaults
 * (`kind`, `recurseDepth`, `maxFiles`).
 */
export function defineGoogleDriveSource(input) {
    return GoogleDriveSourceSchema.parse(input);
}
/**
 * Project a Drive source onto the resolved-source shape, so `loadSource` can
 * return a plain `ResolvedSourceConfig` for Drive too — keeping Drive contained
 * here and sparing every downstream step a source-kind branch.
 *
 * The folder surfaces as `baseUrl` so logs and provenance name the real source
 * (not the Sanity production default). Sanity-only coordinates stay empty and
 * `perspective` is absent — Drive has no equivalent, and the fetch runs through
 * the Drive preset, not these fields.
 */
export function resolveGoogleDriveSource(source) {
    const baseUrl = `https://drive.google.com/drive/folders/${source.rootFolderId}`;
    return {
        baseUrl,
        dataset: "",
        documentIds: [],
        // No llms.txt: that's an agentic-mode *site* index the agent fetches to
        // discover pages. Drive runs literacy and reads each doc straight through
        // this adapter, so there's no site index — and a fabricated URL would just
        // be stored, never fetched.
        llmsTxt: "",
        name: source.name,
        priorityDomain: "drive.google.com",
        projectId: "",
        studioOrigin: "",
        urls: [],
    };
}
