/**
 * area-summary card — deterministic projection over Report.summary.scores.
 *
 * Pure computation, no LLM call. Produces a human-readable sentence
 * summarizing the number of evaluated areas and their mean composite score.
 *
 * Schema is in the D0045 trust-boundary scan root; `satisfies` clause is
 * mandatory (cards/ is a SCAN_ROOT in check-trust-boundary-satisfies.ts).
 *
 * @see .planning/phases/05-diagnosis-engine-cli-llm-cards/05-AI-SPEC.md §3 lines 569-587
 */
import { z } from "zod";
// ---------------------------------------------------------------------------
// Body schema (D0045 trust boundary — satisfies required)
// ---------------------------------------------------------------------------
export const AreaSummaryBodySchema = z.object({
    summary: z.string().min(1).max(500),
});
// ---------------------------------------------------------------------------
// Generator
// ---------------------------------------------------------------------------
export const generateAreaSummary = async (report) => {
    const scores = report.summary.scores;
    if (!scores || scores.length === 0) {
        return {
            status: "missing",
            cardType: "area-summary",
            reason: "report has no areas",
        };
    }
    const meanScore = scores.reduce((sum, s) => sum + s.totalScore, 0) / scores.length;
    const summary = `Across ${scores.length} areas, mean score ${meanScore.toFixed(1)}.`;
    const body = AreaSummaryBodySchema.parse({ summary });
    return {
        status: "ready",
        cardType: "area-summary",
        body,
        meta: {
            cardVersion: "area-summary@0.1.0",
            generatedAt: new Date().toISOString(),
        },
    };
};
