#!/usr/bin/env bun
/**
 * Reads locales/en.json and generates src/mainview/i18n.types.ts
 * with a TranslationKey union type covering all keys.
 *
 * Usage: bun scripts/i18n-types.ts
 */

import { readFileSync, writeFileSync } from 'fs';
import { resolve } from 'path';

const ROOT = resolve(import.meta.dir, '..');
const EN_PATH = resolve(ROOT, 'locales/en.json');
const OUT_PATH = resolve(ROOT, 'src/mainview/i18n.types.ts');

const en: Record<string, string> = JSON.parse(readFileSync(EN_PATH, 'utf-8'));
const keys = Object.keys(en).sort();

const lines: string[] = [
  '/**',
  ' * Auto-generated by scripts/i18n-types.ts — do not edit manually.',
  ' * Run: bun scripts/i18n-types.ts',
  ' */',
  '',
  'export type TranslationKey =',
];

keys.forEach((key, i) => {
  const prefix = i === 0 ? '  | ' : '  | ';
  const suffix = i === keys.length - 1 ? ';' : '';
  lines.push(`${prefix}'${key}'${suffix}`);
});

lines.push('');

writeFileSync(OUT_PATH, lines.join('\n'), 'utf-8');
console.log(`[i18n-types] Generated ${keys.length} keys -> ${OUT_PATH}`);
