/**
 * slides/08-sandbox-imports.js
 * ----------------------------------------------------------------------------
 * Slide 08 -- Sandbox imports + custom backend stub
 */
'use strict';

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

function buildSandboxImports(pres, theme) {
  const slide = pres.addSlide();
  helpers.slideBase(slide, pres, theme);
  helpers.addHeader(slide, pres, theme, {
    eyebrow: 'STAGE 4',
    sectionNumber: 4,
    title: 'Sandbox: imports + custom',
  });

  helpers.addCodeBlock(slide, pres, theme, {
    x: 0.5, y: layouts.CONTENT_TOP, w: 5.0, h: 3.4,
    language: 'python',
    code: [
      'from open_swe.sandbox import (',
      '    ModalBackend,',
      '    DaytonaBackend,',
      '    RunloopBackend,',
      '    LangSmithBackend,',
      ')',
      '',
      '# Modal (Python-first, GPU)',
      'backend = ModalBackend(',
      '    token_id="..."',
      '    token_secret="..."',
      ')',
    ].join('\n'),
    filePath: 'open_swe/sandbox/__init__.py',
    startLine: 1,
  });

  helpers.addCodeBlock(slide, pres, theme, {
    x: 5.7, y: layouts.CONTENT_TOP, w: 3.8, h: 3.4,
    language: 'python',
    code: [
      '# свой backend: devbox-пул',
      'from open_swe.sandbox import (',
      '    SandboxBackend,',
      ')',
      '',
      'class MyInternalBackend(SandboxBackend):',
      '    def execute(self, cmd):',
      '        return self._run(cmd)',
      '',
      '    def read_file(self, p):',
      '        return self._fetch(p)',
    ].join('\n'),
    filePath: 'examples/my_internal_backend.py',
    startLine: 1,
    highlightLines: [5, 8, 9, 11, 12, 13, 14, 15],
  });

  helpers.addCodeBlock(slide, pres, theme, {
    x: 5.7, y: layouts.CONTENT_TOP, w: 3.8, h: 3.4,
    language: 'python',
    code: [
      '# свой backend: devbox-пул',
      'from open_swe.sandbox import (',
      '    SandboxBackend,',
      ')',
      '',
      'class MyInternalBackend(',
      '    SandboxBackend',
      '):',
      '    def __init__(self, conn):',
      '        self.conn = conn',
      '',
      '    def execute(self, cmd):',
      '        return self._run(cmd)',
      '',
      '    def read_file(self, p):',
      '        return self._fetch(p)',
    ].join('\n'),
    filePath: 'examples/my_internal_backend.py',
    startLine: 1,
    highlightLines: [11, 12, 13, 14, 15, 16, 19, 20, 21, 22],
  });

  helpers.addPageNumber(slide, pres, theme, 8);
  helpers.addSourceLine(slide, pres, theme, {
    source: 'research/per-tech/openswe.md: 80-86, 250-264',
  });
  return slide;
}

module.exports = { buildSandboxImports };
