// Quick script to check payment methods in database
require('dotenv').config();
const mysql = require('mysql2/promise');

async function checkPaymentMethods() {
  const pool = mysql.createPool({
    host: process.env.DB_HOST,
    user: process.env.DB_USER,
    password: process.env.DB_PASSWORD,
    database: process.env.DB_NAME,
    port: process.env.DB_PORT || 3306,
    waitForConnections: true,
    connectionLimit: 10,
  });

  try {
    const [rows] = await pool.execute(
      'SELECT id, name, code, is_active, is_automated, display_order FROM payment_methods ORDER BY display_order'
    );

    console.log('\n📋 Payment Methods in Database:\n');
    console.log('─'.repeat(80));
    console.log('ID | Name              | Code          | Active | Auto | Order');
    console.log('─'.repeat(80));

    rows.forEach(row => {
      console.log(
        `${String(row.id).padEnd(3)}| ${String(row.name).padEnd(18)}| ${String(row.code).padEnd(14)}| ${row.is_active ? '✅' : '❌'}    | ${row.is_automated ? '✅' : '❌'}  | ${row.display_order}`
      );
    });

    console.log('─'.repeat(80));
    console.log(`\nTotal: ${rows.length} payment methods\n`);

    // Check if bank_transfer exists
    const bankTransfer = rows.find(r => r.code === 'bank_transfer');
    if (bankTransfer) {
      console.log('✅ Bank Transfer is present in database');
      console.log(`   - ID: ${bankTransfer.id}`);
      console.log(`   - Active: ${bankTransfer.is_active ? 'Yes' : 'No'}`);
      console.log(`   - Display Order: ${bankTransfer.display_order}`);
    } else {
      console.log('❌ Bank Transfer NOT FOUND in database');
      console.log('   Run: node scripts/add-payment-methods.js');
    }

    await pool.end();
  } catch (error) {
    console.error('Error:', error.message);
    process.exit(1);
  }
}

checkPaymentMethods();
