/**
 * Content update, 29 September 2026, second pass: the pricing and about pages, for the same reason as the
 * home page — they were written when there was one course.
 *
 * Pricing said «the four lessons» and «the seven units» and carried one price as though it were the price.
 * With courses across subjects and stages there is no such thing: each course states its own price on its own
 * page, and what the pricing page can say for all of them is the shape — a whole first unit free, then the
 * course, paid once for the school year, through the platform.
 *
 * About said the academy builds the Grade 11 programming syllabus. It builds courses; that one is the first.
 * The principle about a Python lab is the same principle in every subject — practise in the subject's own
 * tools rather than read about them — so it is stated that way and keeps the lab as its example.
 *
 *   docker compose --profile tools run --rm -e NODE_ENV=production tools npx tsx src/scripts/2026-09-29-pricing-about.ts
 *
 * Safe to re-run. Writes src/scripts/backup-2026-09-29-pricing-about.json first.
 */
import fs from 'node:fs'
import path from 'node:path'
import { getPayload } from 'payload'
import config from '@payload-config'

type L = 'ar' | 'en'
const payload = await getPayload({ config })
const get = (slug: string, locale: L) => payload.findGlobal({ slug: slug as never, locale, depth: 0 }) as Promise<any>
const set = (slug: string, locale: L, data: any) =>
  payload.updateGlobal({ slug: slug as never, locale, data, depth: 0 }) as Promise<any>

const SLUGS = ['pricing', 'about']
const backup: Record<string, unknown> = {}
for (const slug of SLUGS) {
  for (const locale of ['ar', 'en'] as L[]) backup[`${slug}.${locale}`] = await get(slug, locale)
}
const file = path.join(process.cwd(), 'src/scripts/backup-2026-09-29-pricing-about.json')
fs.writeFileSync(file, JSON.stringify(backup, null, 2), 'utf8')
console.log(`backup → ${file}`)

const AR = {
  pricing: {
    seo: {
      title: 'الأسعار والتسجيل | أكاديمية Thinkera',
      description:
        'الوحدة الأولى كاملة مجاناً في أي منهج، وكل منهج سعره مكتوب في صفحته، والدفع بإنستاباي من المنصة.',
    },
    lead:
      'الوحدة الأولى كاملة مجاناً في أي منهج. وبعدها كل منهج ليه سعره مكتوب في صفحته، بتدفعه مرة واحدة للعام الدراسي بإنستاباي من المنصة.',
    plans: [
      {
        name: 'الوحدة الأولى',
        text: 'وحدة كاملة بدروسها، في أي منهج، من غير أي اشتراك.',
        price: 'مجاناً',
        items: [
          { text: 'فيديوهات دروس الوحدة' },
          { text: 'ملفات كل درس: الملزمة وشيت الأسئلة وإجاباته' },
          { text: 'تدريب كل درس بأسئلته' },
          { text: 'المساعد الذكي بيجاوبك من دروس المنهج' },
        ],
      },
      {
        name: 'المنهج كامل',
        text: 'المنهج كله بوحداته ودروسه، ومعاه كل جديد فيه أول ما ينزل.',
        price: 'سعر كل منهج في صفحته',
        items: [
          { text: 'كل فيديوهات المنهج' },
          { text: 'ملفات كل درس وأوراق عمله' },
          { text: 'بنك الأسئلة كامل، وامتحانات نهاية كل وحدة' },
          { text: 'تتبّع تقدّمك على المنصة درس بدرس' },
          { text: 'أسئلتك للمدرب، والجلسات المباشرة' },
        ],
      },
    ],
  },
  about: {
    seo: {
      title: 'عن الأكاديمية | أكاديمية Thinkera',
      description:
        'مين ورا أكاديمية Thinkera، وإزاي بيتبني كل درس من الستوري بورد للفيديو وملفات الدرس وبنك الأسئلة، وإيه اللي بننشره وإمتى.',
    },
    lead:
      'أكاديمية Thinkera بتبني مناهج المرحلتين الإعدادية والثانوية زي ما هي في المقرر الرسمي، وبتزوّد فوقها اللي بيجهّز الطالب لما بعد الامتحان. منهج البرمجة والذكاء الاصطناعي أولها، والطريقة واحدة في كل اللي بعده.',
    principlesTitle: 'القواعد اللي بنبني بيها كل درس',
    principles: [
      { text: 'مابنفقدش حرف من المقرر: كل تعريف وسؤال ومصطلح بيفضل بترقيمه وصياغته، والإضافة طبقة فوقه مش بديل عنه.' },
      { text: 'مافيش تبسيط زيادة عن اللزوم: اللي المقرر ذكره في سطر، بنشرحه بآليته وخطواته ومثاله.' },
      { text: 'موقف من الحياة اليومية في كل درس، مش مثال مجرّد من غير سياق.' },
      { text: 'الطالب بيتدرّب بأدوات المادة نفسها مش بالكلام عنها — زي معمل بايثون في المنهج المتقدم للبرمجة.' },
      { text: 'اللي برّه المقرر بيفضل مفصول وعليه علامته، عشان الطالب يفرّق بين اللي هيتمتحن فيه واللي زيادة.' },
    ],
  },
}

const EN = {
  pricing: {
    seo: {
      title: 'Pricing and enrolment | Thinkera Academy',
      description:
        'The whole of Unit 1 free in every course, each course with its own price on its own page, paid through the platform.',
    },
    lead:
      'The whole of Unit 1 is free in every course. After that each course has its own price, stated on its own page and paid once for the school year through the platform.',
    plans: [
      {
        name: 'Unit 1',
        text: 'A whole unit with its lessons, in any course, with no subscription.',
        price: 'Free',
        items: [
          { text: "The unit's lesson videos" },
          { text: "Each lesson's files: the booklet, the question sheet and its answers" },
          { text: "Each lesson's practice and its questions" },
          { text: 'The AI assistant, answering from the course itself' },
        ],
      },
      {
        name: 'The whole course',
        text: 'The course in full, with everything added to it as it arrives.',
        price: 'Each course states its price',
        items: [
          { text: "All of the course's videos" },
          { text: "Every lesson's files and worksheets" },
          { text: 'The full question bank, and an exam at the end of every unit' },
          { text: 'Your progress on the platform, lesson by lesson' },
          { text: 'Your questions to the instructor, and the live sessions' },
        ],
      },
    ],
  },
  about: {
    seo: {
      title: 'About | Thinkera Academy',
      description:
        'Who is behind Thinkera Academy, how each lesson is built from storyboard to video, files and question bank, and what we publish and when.',
    },
    lead:
      'Thinkera Academy builds courses for preparatory and secondary school exactly as the official syllabus has them, and adds above them what prepares a student for after the exam. The programming and AI course is the first; the method is the same in everything that follows.',
    principlesTitle: 'The rules every lesson is built by',
    principles: [
      { text: 'Not a word of the syllabus is lost: every definition, question and term keeps its numbering and its wording, and what we add is a layer above it, never a replacement.' },
      { text: 'No over-simplifying: what the syllabus states in a line, we explain with its mechanism, its steps and its example.' },
      { text: 'A situation from daily life in every lesson, not an abstract example with no context.' },
      { text: "Students practise in the subject's own tools rather than reading about them — the Python lab in the advanced programming track is one example." },
      { text: 'Anything outside the syllabus stays separate and marked, so a student can tell what is examinable from what is extra.' },
    ],
  },
}

const merge = (now: any, next: any) => {
  const out: any = {}
  for (const [k, v] of Object.entries(next)) {
    out[k] = v && typeof v === 'object' && !Array.isArray(v) ? { ...(now?.[k] || {}), ...(v as object) } : v
  }
  return out
}

for (const [locale, copy] of [['ar', AR], ['en', EN]] as [L, any][]) {
  for (const slug of SLUGS) {
    const now = await get(slug, locale)
    await set(slug, locale, merge(now, copy[slug]))
    console.log(`${slug}.${locale} ← ${Object.keys(copy[slug]).join(', ')}`)
  }
}

console.log('done')
process.exit(0)
