import { initDatabase, PlatformAccount } from '../models/index.js';
import { logger } from '../utils/logger.js';
import { WeixinVideoDataCenterImportService } from '../services/WeixinVideoDataCenterImportService.js';

async function main() {
  try {
    await initDatabase();

    const accountName = '凝光AI';
    const accountRepository = (await import('../models/index.js')).AppDataSource.getRepository(
      PlatformAccount
    );

    const account = await accountRepository.findOne({
      where: {
        platform: 'weixin_video' as any,
        accountName,
      },
    });

    if (!account) {
      logger.error(`[WX Import] Weixin video account not found for name=${accountName}`);
      process.exit(1);
      return;
    }

    logger.info(
      `[WX Import] Single-account run start. accountId=${account.id} name=${account.accountName}`
    );

    const svc = new WeixinVideoDataCenterImportService();
    await svc.importAccountLast30Days(account);

    logger.info(
      `[WX Import] Single-account run done. accountId=${account.id} name=${account.accountName}`
    );
    process.exit(0);
  } catch (e) {
    logger.error('[WX Import] Single-account run failed:', e);
    process.exit(1);
  }
}

void main();

