const { deployPages } = require('../lib/deploy-pages');

/**
 * CLI 命令处理函数
 */
async function deployPagesCommand(cname, directory, options) {
  console.log('\n📋 部署配置：');
  console.log(`   域名: ${cname}`);
  console.log(`   目录: ${directory}`);
  if (options.visibility) console.log(`   权限: ${options.visibility}`);
  if (options.description) console.log(`   描述: ${options.description}`);
  if (options.apiKey) console.log('   API Key: ***（已通过参数传入）');
  console.log('');

  if (options.dryRun) {
    console.log('🔍 [dry-run] 预览模式');
  }

  console.log('🚀 开始部署...');

  const result = await deployPages({
    cname,
    directory,
    apiKey: options.apiKey,
    visibility: options.visibility,
    description: options.description,
    dryRun: options.dryRun,
  });

  if (result.success) {
    console.log('\n🎉 部署完成！');
    console.log(`   📄 文件数: ${result.totalFiles}`);
    console.log(`   📦 批次数: ${result.totalBatches}`);
    console.log(`   🌐 访问: ${result.url}`);
    console.log(`   ⚙️  管理: ${result.adminUrl}`);
    if (result.error) {
      console.log(`   ⚠️  ${result.error}`);
    }
  } else {
    console.error(`\n❌ 部署失败: ${result.error}`);
    process.exit(1);
  }
}

module.exports = { deployPagesCommand };
