/**
 * slides/11-github-app.js
 * ----------------------------------------------------------------------------
 * Slide 11 -- GitHub App setup
 * Manifest + permissions.
 */
'use strict';

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

function buildGithubApp(pres, theme) {
  const slide = pres.addSlide();
  helpers.slideBase(slide, pres, theme);
  helpers.addHeader(slide, pres, theme, {
    eyebrow: 'STAGE 4',
    sectionNumber: 4,
    title: 'GitHub App: manifest',
  });

  helpers.addCodeBlock(slide, pres, theme, {
    x: 0.5, y: layouts.CONTENT_TOP, w: 5.7, h: 3.5,
    language: 'yaml',
    code: [
      '# github-app-manifest.yaml',
      'name: open-swe-internal',
      'url: https://open-swe.example.com',
      'hook_attributes:',
      '  url: https://open-swe.example.com/',
      '    webhooks/github',
      '  events:',
      '    - issue_comment',
      '    - pull_request',
      '    - pull_request_review',
      'default_permissions:',
      '  contents: write',
      '  pull_requests: write',
    ].join('\n'),
    filePath: 'config/github-app-manifest.yaml',
    startLine: 1,
    highlightLines: [3, 4, 5, 6, 7, 8, 9],
  });

  helpers.addCallout(slide, pres, theme, {
    x: 6.4, y: layouts.CONTENT_TOP, w: 3.1, h: 1.5,
    kind: 'info',
    title: 'Создание App',
    text:
      '1. github.com/settings/apps/new\n' +
      '2. вставить manifest\n' +
      '3. запомнить App ID\n' +
      '4. скачать private key',
  });

  helpers.addCallout(slide, pres, theme, {
    x: 6.4, y: 2.85, w: 3.1, h: 2.0,
    kind: 'warning',
    title: 'Permissions',
    text:
      'contents:write -- ветки\n' +
      'pull_requests:write -- draft PR\n' +
      'issues:write -- комментарии\n' +
      'metadata:read -- repo info',
  });

  helpers.addPageNumber(slide, pres, theme, 11);
  helpers.addSourceLine(slide, pres, theme, {
    source: 'docs.github.com/apps/creating-github-apps',
  });
  return slide;
}

module.exports = { buildGithubApp };
