import assert from 'node:assert/strict';
import test from 'node:test';

import { assertFileExists, readText } from './helpers.ts';

test('setup plugin registry files exist', () => {
  for (const file of [
    'src/features/setup/plugins/plugin-types.ts',
    'src/features/setup/plugins/plugin-registry.ts',
    'src/features/setup/plugins/installation-profile.ts',
    'src/features/setup/plugins/foundation/foundation-plugin.ts',
    'src/features/setup/plugins/crm/crm-setup-plugin.ts',
    'src/features/setup/plugins/crm/crm-installation-profile.ts'
  ]) {
    assertFileExists(file);
  }
});

test('installation profile API remains available while wizard uses configured import source', () => {
  assertFileExists('src/app/api/setup/profiles/route.ts');

  const wizard = readText('src/features/setup/components/setup-wizard.tsx');
  assert.match(wizard, /setupTemplatesQueryOptions/);
  assert.match(wizard, /Configured Import Folder/);
  assert.match(wizard, /source\.envKey/);
});

test('template API exposes plugin-aware metadata without removing legacy fields', () => {
  const route = readText('src/app/api/setup/templates/route.ts');

  assert.match(route, /plugin/);
  assert.match(route, /profiles/);
  assert.match(route, /requiredColumns/);
  assert.match(route, /importOrder/);
});
