#!/usr/bin/env tsx
/**
 * 测试视频号作品每日数据同步（不依赖 Python，Node 端 Playwright）
 * 用法: cd server && pnpm exec tsx src/scripts/test-weixin-work-daily-sync.ts [workId]
 */
import { initDatabase } from '../models/index.js';
import { logger } from '../utils/logger.js';
import { WeixinVideoWorkStatisticsImportService } from '../services/WeixinVideoWorkStatisticsImportService.js';

async function main() {
  const workId = Number(process.argv[2] || 906);
  await initDatabase();

  logger.info(`测试同步 work_id=${workId}（Node Playwright，showBrowser=true）`);

  try {
    const result = await WeixinVideoWorkStatisticsImportService.runDailyImportForWork(
      workId,
      true
    );
    logger.info(`成功: inserted=${result.inserted}, updated=${result.updated}`);
    process.exit(0);
  } catch (e) {
    logger.error('失败:', e);
    process.exit(1);
  }
}

main().catch((e) => {
  logger.error(e);
  process.exit(1);
});
