import { pgQuery } from '../lib/postgres/client';

async function main() {
  const target = 'S/2026/0031';
  const exact = await pgQuery<any>(
    `SELECT id, invoice_number, invoice_date, status, raw->>'_type' as type_field, raw->>'documentType' as document_type FROM invoices WHERE invoice_number = $1`,
    [target]
  );
  const pref = await pgQuery<any>(`SELECT COUNT(*)::int as c FROM invoices WHERE invoice_number LIKE 'S/2026/%'`);
  console.log('EXACT_COUNT', exact.rows.length);
  console.log('EXACT_ROWS', JSON.stringify(exact.rows, null, 2));
  console.log('S_PREFIX_COUNT', pref.rows[0]?.c ?? 0);
}

main().catch((e) => {
  console.error('ERR', e?.message || e);
  process.exit(1);
});
