/**
 * Synthesis cost telemetry types — canonical TS-first shapes for
 * Phase 6 DIAG-06 cost and parse-failure observability.
 *
 * These interfaces are authored independently of their Zod adapter schema
 * (Plan 06-02) per D0045: the Zod schema declares
 * `satisfies z.ZodType<SynthesisCostTelemetry>` against this independent
 * type so drift is a build error, not a runtime bug.
 *
 * The 14 attribute paths on `SynthesisCostTelemetry` + `SynthesisPerCardTelemetry`
 * land on the `ailf.report` Sanity doc under `summary.synthesis.diagnosis.*`
 * (D6-09). No new sibling doc type (D0033 / D6-09).
 *
 * @see docs/decisions/D0045-type-architecture-and-contract-enforcement.md
 * @see .planning/phases/06-post-run-integration-cost-telemetry/06-CONTEXT.md §D6-09
 * @see .planning/phases/06-post-run-integration-cost-telemetry/06-CONTEXT.md §D6-12
 */
import type { CardType } from "./diagnosis.js";
/**
 * Per-card telemetry row for the `synthesis_per_card` Airbyte stream
 * (D6-11) and the `summary.synthesis.diagnosis.perCard[]` Sanity doc path
 * (D6-09).
 *
 * Fields map directly to the 8 per-card attribute paths in D6-09:
 * `…perCard[].cardType`, `…perCard[].cost`, `…perCard[].parseFailed`,
 * `…perCard[].latencyMs`, `…perCard[].tokenInput`, `…perCard[].tokenOutput`,
 * `…perCard[].cardVersion`, `…perCard[].generatedAt`.
 *
 * `cost` is undefined when the card did not make an LLM call (deterministic
 * cards) and contributes 0 to the roll-up.
 */
export interface SynthesisPerCardTelemetry {
    /** Card archetype — reuses `CardType` from diagnosis.ts:55-63; not redeclared. */
    cardType: CardType;
    /**
     * Per-call USD cost captured from `LLMStructuredCompletion.cost`.
     * `undefined` for deterministic cards (area-summary, failure-mode-summary,
     * no-issues) which make no LLM call.
     */
    cost?: number;
    /**
     * Whether the card's Zod schema parse failed (produces a degraded card).
     * Used for the 7-day rolling parse-failure rate in BigQuery (D6-15).
     */
    parseFailed: boolean;
    /**
     * End-to-end latency for the LLM call in milliseconds.
     * `undefined` for deterministic cards.
     */
    latencyMs?: number;
    /**
     * Prompt tokens consumed by the LLM call.
     * `undefined` for deterministic cards.
     */
    tokenInput?: number;
    /**
     * Completion tokens produced by the LLM call.
     * `undefined` for deterministic cards.
     */
    tokenOutput?: number;
    /** Per-card version string (e.g. `"top-recommendations@0.1.0"`). */
    cardVersion: string;
    /** ISO 8601 UTC timestamp when this card was generated. */
    generatedAt: string;
}
/**
 * Aggregate synthesis cost telemetry for a single Diagnosis run.
 * Lands on the `ailf.report` Sanity doc under `summary.synthesis.diagnosis.*`
 * (D6-09 / D6-10: parallel to `summary.overall.cost` — not additive).
 *
 * Written by the post-run hook (D6-08); not written by standalone
 * `ailf interpret`.
 *
 * Field set matches the 4 top-level D6-09 attribute paths:
 * `summary.synthesis.diagnosis.cost`,
 * `summary.synthesis.diagnosis.parseFailureCount`,
 * `summary.synthesis.diagnosis.parseFailureRate`,
 * `summary.synthesis.diagnosis.perCard`.
 */
export interface SynthesisCostTelemetry {
    /**
     * Total USD cost across all LLM cards in this Diagnosis run.
     * Roll-up: `sum(perCard[].cost ?? 0)` for ready + degraded cards.
     * Missing cards contribute 0.
     */
    cost: number;
    /**
     * Number of cards whose Zod parse failed in this Diagnosis run.
     * Counted across all 8 card types (including deterministic cards;
     * a deterministic-card parse failure indicates a code bug).
     */
    parseFailureCount: number;
    /**
     * Parse-failure rate: `parseFailureCount / 8` (8 = fixed card registry size).
     * Range: 0–1. Used as the denominator for the D6-15 BigQuery 7-day
     * rolling rate view (`synthesis_parse_failure_rate_7d.sql`).
     */
    parseFailureRate: number;
    /** Per-card telemetry rows — one entry per card in registry-order. */
    perCard: SynthesisPerCardTelemetry[];
}
