/**
 * Verify imported data
 */
import { rawQuery } from '../src/db.js';
import dotenv from 'dotenv';

dotenv.config();

async function verifyData() {
  console.log('🔍 Verifying imported data...\n');

  try {
    // Check OptionsFlow_monthly
    const flowCount = await rawQuery('SELECT COUNT(*) as count FROM "OptionsFlow_monthly"');
    console.log(`✅ OptionsFlow_monthly: ${flowCount[0].count} records`);

    const flowSample = await rawQuery('SELECT "Symbol", "CallPut", "Premium", "CreatedDate" FROM "OptionsFlow_monthly" LIMIT 5');
    console.log('   Sample records:');
    flowSample.forEach(row => {
      console.log(`   - ${row.Symbol} ${row.CallPut} | Premium: ${row.Premium} | Date: ${row.CreatedDate}`);
    });

    // Check OptionsVolume
    const volumeCount = await rawQuery('SELECT COUNT(*) as count FROM "OptionsVolume"');
    console.log(`\n✅ OptionsVolume: ${volumeCount[0].count} records`);

    const volumeSample = await rawQuery('SELECT "SYMBOL", "VOL", "RATIO" FROM "OptionsVolume" LIMIT 5');
    console.log('   Sample records:');
    volumeSample.forEach(row => {
      console.log(`   - ${row.SYMBOL} | VOL: ${row.VOL} | Ratio: ${row.RATIO}`);
    });

    // Check OptionsOpenInterest
    const oiCount = await rawQuery('SELECT COUNT(*) as count FROM "OptionsOpenInterest"');
    console.log(`\n✅ OptionsOpenInterest: ${oiCount[0].count} records`);

    const oiSample = await rawQuery('SELECT "SYMBOL", "EXP", "C/P", "STRIKE", "OI" FROM "OptionsOpenInterest" LIMIT 5');
    console.log('   Sample records:');
    oiSample.forEach(row => {
      console.log(`   - ${row.SYMBOL} ${row['C/P']} ${row.STRIKE} | OI: ${row.OI} | Exp: ${row.EXP}`);
    });

    // Check unique symbols
    const symbols = await rawQuery('SELECT COUNT(DISTINCT "Symbol") as count FROM "OptionsFlow_monthly"');
    console.log(`\n📊 Unique symbols in OptionsFlow: ${symbols[0].count}`);

    console.log('\n✅ Data verification complete!');
    console.log('\n🚀 You can now start the server: npm run dev');

  } catch (error) {
    console.error('❌ Verification error:', error.message);
    process.exit(1);
  }
}

verifyData();

