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

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

describe('club module boundary', () => {
  it('does not import other module internals directly', () => {
    const dir = new URL('..', import.meta.url);
    for (const file of sourceFiles(dir.pathname)) {
      const source = readFileSync(file, 'utf8');
      expect(source).not.toMatch(
        /modules\/(identity|users|catalog|inventory|pricing|promotions|cart|shipping|orders|payments|notifications|reviews|cms|security|pos|reporting|store-settings)\/(api|application|domain|infrastructure|tests)/,
      );
    }
  });
});
