/**
 * 配置检查工具
 * 运行：node check-config.js windsurf
 */

const siteName = process.argv[2] || 'windsurf';
const sitePrefix = siteName.toUpperCase().replace(/-/g, '_');

console.log('🔍 Configuration Checker\n');
console.log(`Site: ${siteName}\n`);

// 检查AdsPower
console.log('📌 AdsPower Config:');
console.log(`  ADSPOWER_USER_ID: ${process.env.ADSPOWER_USER_ID ? '✅ Set' : '❌ Missing'}`);
console.log(`  ADSPOWER_API: ${process.env.ADSPOWER_API || 'http://local.adspower.net:50325 (default)'}\n`);

// 检查账号信息
console.log(`📌 ${siteName} Account:`);
const fields = ['EMAIL', 'PASSWORD', 'FIRSTNAME', 'LASTNAME', 'USERNAME', 'PHONE'];

fields.forEach(field => {
  const envKey = `${sitePrefix}_${field}`;
  const value = process.env[envKey];
  const status = value ? '✅' : '⚠️';
  const display = value ? (field.includes('PASSWORD') ? '***' : value) : 'Not set';
  console.log(`  ${envKey}: ${status} ${display}`);
});

// 检查配置文件
const fs = require('fs');
const path = require('path');
const configPath = path.join(__dirname, 'configs', 'sites', `${siteName}.yaml`);

console.log(`\n📌 Config File:`);
console.log(`  Path: ${configPath}`);
console.log(`  Exists: ${fs.existsSync(configPath) ? '✅' : '❌'}`);

// 总结
console.log('\n' + '='.repeat(60));
const adsOk = !!process.env.ADSPOWER_USER_ID;
const emailOk = !!process.env[`${sitePrefix}_EMAIL`];
const passOk = !!process.env[`${sitePrefix}_PASSWORD`];
const configOk = fs.existsSync(configPath);

if (adsOk && emailOk && passOk && configOk) {
  console.log('✅ Ready to run!');
  console.log(`\nRun: pnpm run run -- ${siteName}`);
} else {
  console.log('❌ Missing required configuration:');
  if (!adsOk) console.log('  - Set ADSPOWER_USER_ID');
  if (!emailOk) console.log(`  - Set ${sitePrefix}_EMAIL`);
  if (!passOk) console.log(`  - Set ${sitePrefix}_PASSWORD`);
  if (!configOk) console.log(`  - Add ${siteName}.yaml to configs/sites/`);
}
console.log('='.repeat(60));
