/**
 * slides/19-three-graphs.js
 * ----------------------------------------------------------------------------
 * Slide 19 -- Three graphs: agent / reviewer / analyzer
 * Multi-graph architecture.
 */
'use strict';

const { helpers, layouts } = require('../../design-system');

function buildThreeGraphs(pres, theme) {
  const slide = pres.addSlide();
  helpers.slideBase(slide, pres, theme);
  helpers.addHeader(slide, pres, theme, {
    eyebrow: 'STAGE 4',
    sectionNumber: 4,
    title: 'Three graphs',
  });

  const graphs = [
    {
      name: 'agent graph',
      desc: 'Основной deep-agent: planner + coder + tools + subagents.',
      nodes: 'START -> plan -> execute -> review -> open_pr -> END',
    },
    {
      name: 'reviewer graph',
      desc: 'CI-стиль: lint, type-check, tests, security-scan. Без LLM-агента.',
      nodes: 'START -> run_ci -> parse -> report -> END',
    },
    {
      name: 'analyzer graph',
      desc: 'Анализ ретроспективы: что заняло больше шагов, где loop, где cost spikes.',
      nodes: 'START -> load_trace -> aggregate -> summarize -> END',
    },
  ];

  const cardY = layouts.CONTENT_TOP;
  const cardW = 9.0;
  const cardH = 1.05;
  const gap = 0.13;

  graphs.forEach(function (g, idx) {
    const cy = cardY + idx * (cardH + gap);

    slide.addShape(pres.ShapeType.roundRect, {
      x: 0.5, y: cy, w: cardW, h: cardH,
      fill: { color: theme.palette.bg.elevated },
      line: { color: theme.palette.border.subtle, width: 0.75 },
      rectRadius: 0.08,
    });

    // Name badge
    slide.addShape(pres.ShapeType.rect, {
      x: 0.6, y: cy + 0.12, w: 2.4, h: 0.4,
      fill: { color: theme.palette.accent.primary },
      line: { color: theme.palette.accent.primary, width: 1 },
      rectRadius: 0.04,
    });
    slide.addText(g.name, {
      x: 0.6, y: cy + 0.12, w: 2.4, h: 0.4,
      fontFace: helpers.withFallback(theme.fonts.code),
      fontSize: theme.sizes.code,
      color: theme.palette.text.inverse,
      bold: true,
      align: 'center',
      valign: 'middle',
    });

    // Desc
    slide.addText(g.desc, {
      x: 3.1, y: cy + 0.1, w: 6.3, h: 0.4,
      fontFace: helpers.withFallback(theme.fonts.ui),
      fontSize: theme.sizes.body,
      color: theme.palette.text.secondary,
      valign: 'middle',
    });

    // Node line
    slide.addText(g.nodes, {
      x: 0.6, y: cy + 0.6, w: cardW - 0.2, h: 0.4,
      fontFace: helpers.withFallback(theme.fonts.code),
      fontSize: theme.sizes.code,
      color: theme.palette.text.primary,
      valign: 'middle',
    });
  });

  helpers.addPageNumber(slide, pres, theme, 19);
  helpers.addSourceLine(slide, pres, theme, {
    source: 'research/per-tech/openswe.md: 165, 226-247',
  });
  return slide;
}

module.exports = { buildThreeGraphs };
