import { defineHandler } from '@kb-labs/sdk';
import { loadBaseline, loadHistory } from '@kb-labs/qa-core';
import { getCheckIcon, getCheckLabel } from '@kb-labs/qa-contracts';

// src/rest/handlers/summary-handler.ts
var summary_handler_default = defineHandler({
  async execute(ctx, _input) {
    const baseline = loadBaseline(ctx.cwd);
    const history = loadHistory(ctx.cwd);
    const latest = history.length > 0 ? history[history.length - 1] : null;
    const checkKeys = latest ? Object.keys(latest.summary) : [];
    const checks = checkKeys.map((ct) => ({
      checkType: ct,
      label: getCheckLabel(ct),
      icon: getCheckIcon(ct),
      passed: latest?.summary[ct]?.passed ?? 0,
      failed: latest?.summary[ct]?.failed ?? 0,
      skipped: latest?.summary[ct]?.skipped ?? 0,
      total: (latest?.summary[ct]?.passed ?? 0) + (latest?.summary[ct]?.failed ?? 0) + (latest?.summary[ct]?.skipped ?? 0)
    }));
    return {
      status: latest?.status ?? "unknown",
      lastRunAt: latest?.timestamp ?? null,
      git: latest?.git ?? null,
      checks,
      hasBaseline: baseline !== null,
      baselineTimestamp: baseline?.timestamp ?? null,
      historyCount: history.length
    };
  }
});

export { summary_handler_default as default };
//# sourceMappingURL=summary-handler.js.map
//# sourceMappingURL=summary-handler.js.map