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

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

test('CSV commit API seed manifest integration exist', () => {
  assertFileExists('src/app/api/setup/import/commit/route.ts');
  assertFileExists('src/features/setup/server/seed-manifest.service.ts');

  const route = readText('src/app/api/setup/import/commit/route.ts');
  assert.match(route, /createCsvImportSeedManifest/);
  assert.match(route, /!dryRun/);
});

test('commit engine keeps preview hash validation contract', () => {
  const service = readText('src/features/setup/server/csv-commit.service.ts');

  assert.match(service, /PREVIEW_HASH_REQUIRED/);
  assert.match(service, /PREVIEW_HASH_MISMATCH/);
});

test('organization CSV import uses deterministic UUID primary keys', () => {
  const executor = readText('src/features/setup/server/csv/upsert-executor.ts');

  assert.match(executor, /function deterministicOrganizationId/);
  assert.match(executor, /deterministicId\(`organization:\$\{normalized\}`\)/);
  assert.match(executor, /const id = deterministicOrganizationId\(values\.organization_code\)/);
  assert.doesNotMatch(executor, /const id = normalizeOrganizationCode\(values\.organization_code\)/);
});
