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);
    if (statSync(path).isDirectory()) {
      return sourceFiles(path);
    }
    return path.endsWith('.ts') ? [path] : [];
  });
}

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

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