/**
 * eval-config-json-schema.ts — derive the published `EvalConfig` JSON Schema
 * from the runtime Zod validator (D0090 / D0045).
 *
 * `buildEvalConfigJsonSchema()` converts `EvalConfigSchema` to a JSON Schema
 * via Zod 4's built-in `z.toJSONSchema()` — the SAME schema object the
 * `--config` loader parses with, so the published schema cannot drift from
 * the validator. The generator script (`scripts/generate-eval-config-schema.ts`)
 * writes the output to `docs/schemas/eval-config.schema.json`, and a vitest
 * regenerates it in-memory and asserts equality with the committed file, so
 * drift is a test failure rather than a silent doc/code split.
 *
 * The `$id` / `title` / `$schema` envelope is added here (Zod emits the body
 * only) so an editor pointed at the file via `$schema` gets autocomplete and
 * validation against the canonical id.
 */
import { z } from "zod";
import { EvalConfigSchema } from "./eval-config.js";
/**
 * Canonical published location of the schema, used as its `$id`. Editors
 * resolve `"$schema"` references in committed configs against this id.
 */
export const EVAL_CONFIG_SCHEMA_ID = "https://raw.githubusercontent.com/sanity-labs/ai-literacy-framework/main/docs/schemas/eval-config.schema.json";
/**
 * Build the published `EvalConfig` JSON Schema from the runtime validator.
 *
 * Deterministic: same Zod schema in, byte-identical JSON object out, so the
 * drift test can compare against the committed file without normalization.
 */
export function buildEvalConfigJsonSchema() {
    const body = z.toJSONSchema(EvalConfigSchema, { target: "draft-7" });
    return {
        $schema: "http://json-schema.org/draft-07/schema#",
        $id: EVAL_CONFIG_SCHEMA_ID,
        title: "AILF EvalConfig",
        description: "Schema for `ailf run --config <file>` evaluation config files. " +
            "Derived from the EvalConfigSchema runtime validator (@sanity/ailf-core) " +
            "so it cannot drift from the code. Generated — do not hand-edit; run " +
            "`pnpm --filter @sanity/ailf-core generate-eval-config-schema`.",
        ...body,
    };
}
/**
 * Serialize the schema exactly as the committed file is written: 2-space
 * indent, trailing newline. Shared by the generator script and the drift
 * test so both agree on formatting.
 */
export function serializeEvalConfigJsonSchema() {
    return `${JSON.stringify(buildEvalConfigJsonSchema(), null, 2)}\n`;
}
