#!/usr/bin/env node
'use strict';

const {
  ensureSqliteDriverReady,
  getSqliteDriverStatus,
} = require('../lib/sqlite-driver');

try {
  ensureSqliteDriverReady({ source: 'sqlite-driver-cli' });
  const status = getSqliteDriverStatus();
  console.log(JSON.stringify({
    ok: true,
    node: status.node,
    node_modules_abi: status.node_modules_abi,
    exec_path: status.exec_path,
    repaired: status.repaired,
    attempts: status.attempts || [],
  }, null, 2));
} catch (error) {
  const status = getSqliteDriverStatus();
  console.error(JSON.stringify({
    ok: false,
    error: error.message,
    classification: error.classification || status.classification,
    node: status.node,
    node_modules_abi: status.node_modules_abi,
    exec_path: status.exec_path,
    attempts: status.attempts || [],
  }, null, 2));
  process.exit(1);
}
