const initSqlJs = require('sql.js');
const fs = require('fs');

initSqlJs().then(SQL => {
    const buffer = fs.readFileSync('E:/var/lib/9router/db/data.sqlite');
    const db = new SQL.Database(buffer);
    
    // Get all connections with provider column
    const result = db.exec("SELECT id, provider, isActive, data FROM providerConnections");
    if (result[0]?.values) {
        console.log('All Provider Connections (with provider column):\n');
        result[0].values.forEach(row => {
            const data = JSON.parse(row[3] || '{}');
            const isMimo = data.baseUrl?.includes('mimo') || data.providerSpecificData?.baseUrl?.includes('mimo');
            if (isMimo || row[1]?.includes('mimo')) {
                console.log(`--- ${row[0]} ---`);
                console.log(`Provider: ${row[1]}`);
                console.log(`isActive: ${row[2]}`);
                console.log(`API Key: ${data.apiKey || data.providerSpecificData?.apiKey || 'NOT FOUND'}`);
                console.log(`Prefix: ${data.prefix || data.providerSpecificData?.prefix}`);
                console.log(`Base URL: ${data.baseUrl || data.providerSpecificData?.baseUrl}`);
                console.log('');
            }
        });
    }
    
    db.close();
    process.exit(0);
});
