import { describe, expect, it } from "bun:test";
import en from "../../messages/en.json";
import fr from "../../messages/fr.json";
import { locales } from "./config";

const catalogs: Record<string, unknown> = { en, fr };

function keyPaths(obj: unknown, prefix = ""): string[] {
  if (obj == null || typeof obj !== "object") return [prefix];
  return Object.entries(obj as Record<string, unknown>).flatMap(([k, v]) =>
    keyPaths(v, prefix ? `${prefix}.${k}` : k),
  );
}

describe("message catalog parity", () => {
  const enKeys = new Set(keyPaths(en));
  for (const loc of locales) {
    if (loc === "en") continue;
    it(`${loc}.json has every en foundation key`, () => {
      const locKeys = new Set(keyPaths(catalogs[loc]));
      const missing = [...enKeys].filter((k) => !locKeys.has(k));
      expect(missing).toEqual([]);
    });
  }
});
