// Auto-generated by scripts/gen_parity_tests.py from docs/runtime-parity.md.
// Module: node:sqlite
// This file is a byte-for-byte parity test against `node --experimental-strip-types`.
// Edit the TODO lines below to exercise each API; rerun
// `./run_parity_tests.sh --filter test_parity_sqlite` to verify.

// node:sqlite is Node 22+ and experimental. Guard the whole file under try/catch
// so a missing module produces a single error line instead of crashing the run.

let DatabaseSync: any;
let constants: any;
let backup: any;
try {
  const sq = await import("node:sqlite");
  DatabaseSync = sq.DatabaseSync;
  constants = (sq as any).constants;
  backup = (sq as any).backup;
  console.log("node:sqlite import: ok");
} catch (e) {
  console.log("node:sqlite import error:", (e as Error).message);
}

// ── Class: DatabaseSync ──
try {
  if (!DatabaseSync) throw new Error("DatabaseSync not available");
  console.log("DatabaseSync typeof:", typeof DatabaseSync);
  const db = new DatabaseSync(":memory:");
  console.log("db typeof:", typeof db);
  console.log("db.isOpen:", db.isOpen);
  console.log("db.location typeof:", typeof db.location);
  console.log("db.aggregate typeof:", typeof db.aggregate);
  console.log("db.function typeof:", typeof db.function);
  console.log("db.loadExtension typeof:", typeof db.loadExtension);
  console.log("db.enableLoadExtension typeof:", typeof db.enableLoadExtension);
  console.log("db.prepare typeof:", typeof db.prepare);
  console.log("db.exec typeof:", typeof db.exec);
  console.log("db.close typeof:", typeof db.close);
  console.log("db.createSession typeof:", typeof db.createSession);
  console.log("db.applyChangeset typeof:", typeof db.applyChangeset);

  // Exec CREATE TABLE
  db.exec("CREATE TABLE t (id INTEGER PRIMARY KEY, name TEXT)");
  console.log("CREATE TABLE: ok");

  // INSERT via prepare().run()
  const ins = db.prepare("INSERT INTO t (name) VALUES (?)");
  const r1 = ins.run("alice");
  console.log("insert alice changes:", r1.changes);
  console.log("insert alice lastInsertRowid:", r1.lastInsertRowid);
  const r2 = ins.run("bob");
  console.log("insert bob changes:", r2.changes);
  console.log("insert bob lastInsertRowid:", r2.lastInsertRowid);

  // SELECT via prepare().all()
  const sel = db.prepare("SELECT * FROM t");
  const rows = sel.all();
  console.log("rows length:", rows.length);
  console.log("row 0 id:", rows[0].id);
  console.log("row 0 name:", rows[0].name);
  console.log("row 1 id:", rows[1].id);
  console.log("row 1 name:", rows[1].name);

  // ── Class: StatementSync — probe more APIs ──
  console.log("stmt.all typeof:", typeof sel.all);
  console.log("stmt.get typeof:", typeof sel.get);
  console.log("stmt.iterate typeof:", typeof sel.iterate);
  console.log("stmt.run typeof:", typeof sel.run);
  console.log("stmt.columns typeof:", typeof sel.columns);
  console.log("stmt.setReadBigInts typeof:", typeof sel.setReadBigInts);
  console.log("stmt.setAllowBareNamedParameters typeof:", typeof sel.setAllowBareNamedParameters);
  console.log("stmt.setAllowUnknownNamedParameters typeof:", typeof sel.setAllowUnknownNamedParameters);
  console.log("stmt.sourceSQL:", sel.sourceSQL);
  console.log("stmt.expandedSQL:", sel.expandedSQL);

  // stmt.get exercises single-row select
  try {
    const one = sel.get();
    console.log("stmt.get row id:", one?.id);
    console.log("stmt.get row name:", one?.name);
  } catch (e) {
    console.log("stmt.get area error:", (e as Error).message);
  }

  db.close();
  console.log("db.close: ok");
} catch (e) {
  console.log("DatabaseSync area error:", (e as Error).message);
}

// ── Class: Session — probe via typeof on a fresh db ──
try {
  if (!DatabaseSync) throw new Error("DatabaseSync not available");
  const db2 = new DatabaseSync(":memory:");
  db2.exec("CREATE TABLE s (id INTEGER PRIMARY KEY, v INTEGER)");
  const session = db2.createSession();
  console.log("session typeof:", typeof session);
  console.log("session.changeset typeof:", typeof session.changeset);
  console.log("session.patchset typeof:", typeof session.patchset);
  console.log("session.close typeof:", typeof session.close);
  session.close();
  db2.close();
} catch (e) {
  console.log("Session area error:", (e as Error).message);
}

// ── Module-Level Functions ──
try {
  console.log("sqlite.backup typeof:", typeof backup);
} catch (e) {
  console.log("backup typeof area error:", (e as Error).message);
}

// ── Constants (`sqlite.constants`) ──
try {
  console.log("constants typeof:", typeof constants);
  console.log("SQLITE_CHANGESET_DATA:", constants?.SQLITE_CHANGESET_DATA);
  console.log("SQLITE_CHANGESET_NOTFOUND:", constants?.SQLITE_CHANGESET_NOTFOUND);
  console.log("SQLITE_CHANGESET_CONFLICT:", constants?.SQLITE_CHANGESET_CONFLICT);
  console.log("SQLITE_CHANGESET_CONSTRAINT:", constants?.SQLITE_CHANGESET_CONSTRAINT);
  console.log("SQLITE_CHANGESET_FOREIGN_KEY:", constants?.SQLITE_CHANGESET_FOREIGN_KEY);
  console.log("SQLITE_CHANGESET_OMIT:", constants?.SQLITE_CHANGESET_OMIT);
  console.log("SQLITE_CHANGESET_REPLACE:", constants?.SQLITE_CHANGESET_REPLACE);
  console.log("SQLITE_CHANGESET_ABORT:", constants?.SQLITE_CHANGESET_ABORT);
} catch (e) {
  console.log("constants area error:", (e as Error).message);
}

// Coverage: 0 auto-emitted, 25 TODO, 0 skip-listed.
