/**
 * Zod adapter schema for SynthesisCostTelemetry at the trust boundary.
 *
 * This schema sits at `packages/eval/src/adapters/**` and is therefore
 * scanned by `pnpm check-trust-boundary-satisfies` (D0045). The
 * `satisfies z.ZodType<SynthesisCostTelemetry>` clause makes schema/type
 * drift a build error, not a runtime bug.
 *
 * Used by:
 * - Plan 06-04 `ReportStore.patchSynthesis` — validates telemetry before
 *   writing to Sanity (process memory → Sanity write boundary, T-06-04).
 * - Any future Sanity-side reader of `summary.synthesis.diagnosis.*`
 *   (Sanity Content Lake → eval process boundary, T-06-04).
 *
 * Security constraints:
 * - No `.passthrough()` — schema is closed to prevent PII leakage from
 *   card body text into the telemetry shape (T-06-05).
 * - Satisfies clause is load-bearing (T-06-06); no exemption marker.
 *
 * @see packages/core/src/types/synthesis-telemetry.ts — independently authored domain types
 * @see docs/decisions/D0045-type-architecture-and-contract-enforcement.md
 * @see .planning/phases/06-post-run-integration-cost-telemetry/06-CONTEXT.md §D6-09
 */
import { z } from "zod";
/**
 * Enum of all valid card types — mirrors `CardType` from diagnosis.ts.
 * Using `z.enum()` (not `z.string()`) so the schema satisfies
 * `z.ZodType<SynthesisPerCardTelemetry>` (which requires `cardType: CardType`).
 */
const CardTypeSchema = z.enum([
    "area-summary",
    "failure-mode-summary",
    "no-issues",
    "top-recommendations",
    "weakest-area",
    "low-confidence-attribution",
    "doc-attribution-spotlight",
    "regression-vs-baseline",
]);
const SynthesisPerCardSchema = z.object({
    cardType: CardTypeSchema,
    cost: z.number().nonnegative().optional(),
    parseFailed: z.boolean(),
    latencyMs: z.number().int().nonnegative().optional(),
    tokenInput: z.number().int().nonnegative().optional(),
    tokenOutput: z.number().int().nonnegative().optional(),
    cardVersion: z.string(),
    generatedAt: z.string().datetime({ offset: false }), // ISO 8601 UTC required
});
export const SynthesisCostTelemetrySchema = z.object({
    cost: z.number().nonnegative(),
    parseFailureCount: z.number().int().nonnegative(),
    parseFailureRate: z.number().min(0).max(1),
    perCard: z.array(SynthesisPerCardSchema),
});
