const fs = require('fs');
const path = require('path');

// 服务目录
const SERVICES_DIR = __dirname;

// 需要重命名的目录（大写 -> 小写）
const DIRECTORY_CASE_FIXES = {
  'AI': 'ai',
  'Analytics': 'analytics',
  'Core': 'core',
  'Logistics': 'logistics',
  'Business': 'business',
  'Infra': 'infra',
  'telemetry': 'telemetry',
  'tenant': 'tenant',
  'utils': 'utils'
};

// 重命名目录
const fixDirectoryCase = () => {
  console.log('Starting directory case fix...');
  
  // 遍历需要重命名的目录
  Object.entries(DIRECTORY_CASE_FIXES).forEach(([oldName, newName]) => {
    const oldPath = path.join(SERVICES_DIR, oldName);
    const newPath = path.join(SERVICES_DIR, newName);
    
    if (fs.existsSync(oldPath) && !fs.existsSync(newPath)) {
      fs.renameSync(oldPath, newPath);
      console.log(`Renamed directory: ${oldName} -> ${newName}`);
    } else if (fs.existsSync(oldPath) && fs.existsSync(newPath)) {
      console.log(`Skipped directory rename: ${oldName} -> ${newName} (new directory already exists)`);
    } else {
      console.log(`Skipped directory rename: ${oldName} -> ${newName} (old directory does not exist)`);
    }
  });
  
  console.log('\nDirectory case fix completed!');
};

// 运行修复
fixDirectoryCase();
