/**
 * 验证生成的卡号是否符合规律
 */

const CardGenerator = require('./src/tools/card-generator/generator');
const Formatter = require('./src/tools/card-generator/formatter');
const { luhnCheck } = require('./src/shared/utils');

const generator = new CardGenerator();
const formatter = new Formatter();

console.log('=== 生成卡号验证 ===\n');

// 生成10张银联卡
console.log('生成10张银联卡进行验证:\n');

const cards = generator.generateBatch(10, 'unionpay');

cards.forEach((card, index) => {
  const isValid = luhnCheck(card.number);
  const status = isValid ? '✓' : '✗';
  const formatted = formatter.format(card, 'pipe');
  console.log(`${index + 1}. ${formatted} ${status}`);
});

console.log('\n=== 验证结果 ===');
const validCount = cards.filter(card => luhnCheck(card.number)).length;
console.log(`Luhn校验: ${validCount}/${cards.length} 通过`);

if (validCount === cards.length) {
  console.log('✓ 所有卡号都通过Luhn校验，符合规律！');
  console.log('\n=== 提供测试卡号 ===');
  const testCard = cards[0];
  console.log('\n请使用以下卡号进行测试：');
  console.log(`\n${formatter.format(testCard, 'pipe')}\n`);
  console.log('详细信息：');
  console.log(formatter.format(testCard, 'pretty'));
} else {
  console.log('✗ 部分卡号未通过校验，需要修复');
}

// 对比格式
console.log('\n=== 格式对比 ===');
console.log('原始样本格式:');
console.log('  6228367546781457|11|27|792');
console.log('\n生成的卡号格式:');
console.log(`  ${formatter.format(cards[0], 'pipe')}`);
console.log('\n格式一致性: ✓');
