import pg from 'pg';

const connectionString = 'postgresql://edumanager:EduManager2026!Seguro@150.230.87.131:5432/edumanager';
const pool = new pg.Pool({ connectionString });

async function run() {
  try {
    const { rows: schoolDataRows } = await pool.query('SELECT length(data::text) as len, (data->\'exams\') is not null as has_exams FROM school_data WHERE id = 1');
    console.log('School Data:', schoolDataRows);
    
    if (schoolDataRows[0]?.has_exams) {
      const { rows: examCount } = await pool.query('SELECT jsonb_array_length(data->\'exams\') as count FROM school_data WHERE id = 1');
      console.log('Quantidade de provas no school_data JSON:', examCount[0]?.count);
    }

    const { rows: countProvas } = await pool.query('SELECT count(*) as count FROM provas');
    console.log('Quantidade de provas na tabela PROVAS (SQL):', countProvas[0]?.count);

    const { rows: countQuestoes } = await pool.query('SELECT count(*) as count FROM questoes_provas');
    console.log('Quantidade de questões na tabela QUESTAO_PROVAS (SQL):', countQuestoes[0]?.count);

  } catch (err) {
    console.error('Erro ao conectar ao banco:', err);
  } finally {
    await pool.end();
  }
}

run();
