/**
 * @sanity/ailf-core — SymbolPreflightReport schema
 *
 * The trust-boundary parser for the W0198 deterministic-lane artifact.
 * Used when reading a previously-emitted preflight report back from
 * disk / GCS so a downstream step (re-grading, comparison, dashboard
 * rendering) can trust its shape.
 *
 * The schema asserts `satisfies z.ZodType<SymbolPreflightReport>`
 * against the domain type in
 * `packages/core/src/types/symbol-preflight-report.ts` (D0045 / W0187),
 * so any drift between the two is a build error.
 */
import { z } from "zod";
const ExistsFindingSchema = z.object({
    result: z.literal("exists"),
    pkg: z.string().min(1),
    version: z.string().min(1),
    binding: z.string().min(1),
    source: z.enum(["types", "runtime"]),
});
const MissingFindingSchema = z.object({
    result: z.literal("missing"),
    pkg: z.string().min(1),
    version: z.string().min(1),
    binding: z.string().min(1),
});
const UnresolvedReasonSchema = z.enum([
    "package-not-installed",
    "types-entry-missing",
    "parse-failed",
    "reexport-hop-unfollowed",
]);
const UnresolvedFindingSchema = z.object({
    result: z.literal("unresolved"),
    pkg: z.string().min(1),
    binding: z.string().min(1),
    reason: UnresolvedReasonSchema,
});
const FindingSchema = z.discriminatedUnion("result", [
    ExistsFindingSchema,
    MissingFindingSchema,
    UnresolvedFindingSchema,
]);
const DeductionSchema = z.object({
    perMissing: z.number().nonnegative(),
    cap: z.number().nonnegative(),
    total: z.number().nonnegative(),
});
export const SymbolPreflightReportSchema = z.object({
    candidate: z.object({
        taskId: z.string().min(1),
        testIndex: z.number().int().nonnegative(),
    }),
    findings: z.array(FindingSchema),
    deduction: DeductionSchema,
});
