#!/usr/bin/env node

const { execSync } = require('child_process');

// Check for --dryRun flag at the beginning
const isDryRun = process.argv.includes('--dryRun');

// Store predefined data
const data = {
  moduleName: 'test',
  name: 't1',
  properties: ['title', 'name'],
  widgets: ['text-editor', 'text-editor'],
  dataTypes: ['string', 'string'],
  required: ['name'],
  colSpans: [6, 6],
  orders: [1, 2],
  icon: 'fa-light fa-default'
};

console.log('\n=== AcoreX Platform Interactive Entity Generator (Test Mode) ===\n');
console.log('Using predefined values:');
console.log(`Module: ${data.moduleName}`);
console.log(`Entity: ${data.name}`);
console.log(`Properties: ${data.properties.join(', ')}`);
console.log(`Required: ${data.required.join(', ')}`);
console.log(`Icon: ${data.icon}`);

// Run the NX generator with the predefined data
function runNxGenerator() {
  // Format the command
  const command = `cd ../../.. && npx nx g @acorex-platform/generator:create-module-entity --moduleName=${data.moduleName} --name=${data.name} --properties=${data.properties.join(',')} --dataTypes=${data.dataTypes.join(',')} --required=${data.required.join(',')} --colSpans=${data.colSpans.join(',')} --orders=${data.orders.join(',')} --icon="${data.icon}"${isDryRun ? ' --dryRun' : ''}`;
  
  console.log(`\nRunning: ${command}`);
  
  try {
    // Execute the command
    const output = execSync(command, { stdio: 'inherit' });
    console.log('\nGenerator completed successfully');
    return 0;
  } catch (error) {
    console.error(`\nGenerator failed with error: ${error.message}`);
    return 1;
  }
}

// Run the generator
process.exit(runNxGenerator()); 