import { readdirSync, readFileSync, statSync } from 'node:fs';
import { join } from 'node:path';
import { describe, expect, it } from 'vitest';

function sourceFiles(dir: string): string[] {
  const entries = readdirSync(dir);
  return entries.flatMap((entry) => {
    const path = join(dir, entry);
    const stat = statSync(path);
    if (stat.isDirectory()) {
      return sourceFiles(path);
    }
    return path.endsWith('.ts') ? [path] : [];
  });
}

describe('inventory module boundary', () => {
  it('keeps catalog isolated from inventory internals and tables (AC3)', () => {
    const catalogDir = new URL('../../catalog', import.meta.url);

    for (const file of sourceFiles(catalogDir.pathname)) {
      const source = readFileSync(file, 'utf8');
      expect(source).not.toContain('inventory_');
      expect(source).not.toMatch(
        /modules\/inventory\/(?:api|application|domain|infrastructure|tests)/,
      );
    }
  });
});
