/**
 * Content update, 25 September 2026: the academy's two contact details change.
 *
 *   email     support@thinkera.academy  →  info@thinkera.academy
 *   WhatsApp  (none / old number)       →  +20 102 590 9340
 *
 * They live in the `settings` global's `contact` group, which the footer and the contact page both read, so
 * changing them here changes every page at once.
 *
 *   docker compose --profile tools run --rm -e NODE_ENV=production \
 *     tools npx tsx src/scripts/2026-09-25-contact.ts
 *
 * NODE_ENV=production matters: without it Payload runs in dev mode, "pushes" the schema and leaves a `dev` row
 * in payload_migrations, and the site then stops at start-up asking whether to continue.
 *
 * Safe to re-run: it sets two fields to a fixed value and reports what each one was. It prints the previous
 * values before writing, so the change can be undone by hand if it was not wanted.
 */
import { getPayload } from 'payload'
import config from '@payload-config'

const payload = await getPayload({ config })

const EMAIL = 'info@thinkera.academy'
// stored with the country code and no punctuation, the way the site's whatsapp() helper expects it
const WHATSAPP = '00201025909340'

const before = (await payload.findGlobal({ slug: 'settings' as never, depth: 0 })) as any
const contact = { ...(before?.contact ?? {}) }

console.log('before:')
console.log('  email:    ' + (contact.email || '(none)'))
console.log('  whatsapp: ' + (contact.whatsapp || '(none)'))

if (contact.email === EMAIL && contact.whatsapp === WHATSAPP) {
  console.log('\nalready set; nothing written')
  process.exit(0)
}

contact.email = EMAIL
contact.whatsapp = WHATSAPP

await payload.updateGlobal({ slug: 'settings' as never, data: { contact } as never })

const after = (await payload.findGlobal({ slug: 'settings' as never, depth: 0 })) as any
console.log('\nafter:')
console.log('  email:    ' + (after?.contact?.email || '(none)'))
console.log('  whatsapp: ' + (after?.contact?.whatsapp || '(none)'))

if (after?.contact?.email !== EMAIL || after?.contact?.whatsapp !== WHATSAPP) {
  console.error('\nthe global did not take the new values; look at it in /admin')
  process.exit(1)
}
console.log('\nwritten')
process.exit(0)
