import test from 'node:test';
import assert from 'node:assert';
import { requireCommonJS } from './_helpers/commonjs-bridge.js';
import { AutoReporter } from './reporters/AutoReporter.js';

// Tests basiques sans appels API ni WebSocket


// Auto-Reporter Configuration
const autoReporter = new AutoReporter();

test('Structure: Selective modules exists and exports', () => {
  // Test que les modules de l'architecture modulaire existent
  const { analyzeTechnicalQuality } = requireCommonJS('selective-enhancement/SelectiveUtils');
  const { applySelectiveLayer } = requireCommonJS('selective-enhancement/SelectiveCore');

  // Vérifier que les fonctions principales existent
  assert.ok(typeof analyzeTechnicalQuality === 'function', 'analyzeTechnicalQuality existe');
  assert.ok(typeof applySelectiveLayer === 'function', 'applySelectiveLayer existe');

  console.log('✅ Architecture modulaire selective validée');
});

test('Structure: Adversarial modules exists and exports', () => {
  // Test que les modules adversariel existent
  const { applyAdversarialLayer } = requireCommonJS('adversarial-generation/AdversarialCore');
  const { applyLayerPipeline } = requireCommonJS('adversarial-generation/AdversarialLayers');

  // Vérifier que les fonctions principales existent
  assert.ok(typeof applyAdversarialLayer === 'function', 'applyAdversarialLayer existe');
  assert.ok(typeof applyLayerPipeline === 'function', 'applyLayerPipeline existe');

  console.log('✅ Architecture modulaire adversarial validée');
});

test('Structure: Fonctions principales existent', () => {
  const modules = [
    'MissingKeywords',
    'selective-enhancement/SelectiveCore', // Architecture modulaire 
    'Main', // Main.js contient maintenant tout le système modulaire
    'BrainConfig'
  ];
  
  // Modules modulaires spécifiques
  const modularModules = [
    'selective-enhancement/SelectiveCore',
    'selective-enhancement/SelectiveLayers',
    'selective-enhancement/SelectiveUtils', // Remplace ContentGeneration
    'adversarial-generation/AdversarialCore',
    'human-simulation/HumanSimulationCore',
    'pattern-breaking/PatternBreakingCore'
  ];
  
  modules.forEach(moduleName => {
    try {
      const module = requireCommonJS(moduleName);
      assert.ok(typeof module === 'object', `${moduleName} est un objet`);
      assert.ok(Object.keys(module).length > 0, `${moduleName} a des exports`);
    } catch (error) {
      assert.fail(`${moduleName} non chargeable: ${error.message}`);
    }
  });
  
  // Vérifier modules modulaires
  modularModules.forEach(moduleName => {
    try {
      const module = requireCommonJS(moduleName);
      assert.ok(typeof module === 'object', `${moduleName} (modulaire) est un objet`);
      assert.ok(Object.keys(module).length > 0, `${moduleName} (modulaire) a des exports`);
    } catch (error) {
      assert.fail(`${moduleName} (modulaire) non chargeable: ${error.message}`);
    }
  });
  
  console.log('✅ Tous les modules principaux chargent correctement');
});

test('Structure: Personnalités configuration existe', () => {
  try {
    const { selectMultiplePersonalitiesWithAI, getPersonalities } = requireCommonJS('BrainConfig');
    
    assert.ok(typeof selectMultiplePersonalitiesWithAI === 'function', 'selectMultiplePersonalitiesWithAI existe');
    assert.ok(typeof getPersonalities === 'function', 'getPersonalities existe');
    
    console.log('✅ Système personnalités configuré');
    
  } catch (error) {
    assert.fail(`Système personnalités non disponible: ${error.message}`);
  }
});

test('Structure: Pipeline modulaire fonctions existent', () => {
  // Vérifier workflow principal modulaire
  const { handleModularWorkflow } = requireCommonJS('Main');
  assert.ok(typeof handleModularWorkflow === 'function', 'Workflow modulaire principal existe');
  
  // Vérifier modules selective enhancement 
  const selectiveCore = requireCommonJS('selective-enhancement/SelectiveCore');
  const { applySelectiveLayer } = selectiveCore;
  assert.ok(typeof applySelectiveLayer === 'function', 'Selective Core Layer existe');
  
  const selectiveLayers = requireCommonJS('selective-enhancement/SelectiveLayers');
  const { applyPredefinedStack, applyAdaptiveLayers } = selectiveLayers;
  assert.ok(typeof applyPredefinedStack === 'function', 'Selective Stacks existe');
  assert.ok(typeof applyAdaptiveLayers === 'function', 'Adaptive Layers existe');
  
  // Vérifier génération simple (remplace ContentGeneration)
  const selectiveUtils = requireCommonJS('selective-enhancement/SelectiveUtils');
  const { generateSimple } = selectiveUtils;
  assert.ok(typeof generateSimple === 'function', 'Génération simple existe');
  
  console.log('✅ Pipeline modulaire structure validée');
});