/**
 * @sanity/ailf-core — Callback Payload schema
 *
 * Defines the formal contract for the payload POSTed to callback URLs
 * after an API-triggered pipeline evaluation completes. This schema is
 * the single source of truth — the CallbackStep produces it, and
 * external consumers (SDK, webhooks) validate against it.
 *
 * The payload is HMAC-SHA256 signed via the X-AILF-Signature header.
 * See packages/eval/src/pipeline/callback-delivery.ts for signature
 * computation.
 *
 * @see packages/eval/src/orchestration/steps/callback-step.ts
 * @see docs/design-docs/api-service-gateway.md
 */
import { z } from "zod";
// ---------------------------------------------------------------------------
// Callback Payload — the delivery contract
// ---------------------------------------------------------------------------
export const CallbackPayloadSchema = z.object({
    /** ISO timestamp of when the callback was delivered */
    deliveredAt: z.string().datetime(),
    /** Job ID for tracking (present for API-triggered evaluations) */
    jobId: z.string().optional(),
    /** Report ID in the Content Lake (present when publish is enabled) */
    reportId: z.string().optional(),
    /** The full score summary from the evaluation */
    summary: z.unknown(),
});
// ---------------------------------------------------------------------------
// Webhook Event Envelope — versioned delivery contract for webhook subscribers
// ---------------------------------------------------------------------------
const WebhookEventReportSchema = z.object({
    reportId: z.string().optional(),
    publishTag: z.string().optional(),
    source: z.string(),
    areas: z.array(z.string()),
    belowCritical: z.array(z.string()),
    regressed: z.array(z.string()),
    degraded: z.boolean(),
    link: z.string().optional(),
});
export const WebhookEventEnvelopeSchema = z.object({
    schemaVersion: z.literal(1),
    deliveredAt: z.string().datetime(),
    surface: z.enum(["per-run", "subscription"]),
    events: z.array(z.string()),
    report: WebhookEventReportSchema,
    jobId: z.string().optional(),
    summary: z.unknown().optional(),
});
