#!/usr/bin/env node
/* eslint-disable no-console */
require('dotenv').config();

const { closeDatabase, openDatabase } = require('../lib/sqlite');
const { ensurePlantSchema, getPlantDiagnostics } = require('../lib/plants');

const main = async () => {
  const db = await openDatabase();
  try {
    await ensurePlantSchema(db);
    const diagnostics = await getPlantDiagnostics(db);
    console.log(JSON.stringify(diagnostics, null, 2));
  } finally {
    await closeDatabase(db);
  }
};

main().catch((error) => {
  console.error('Failed to read plant diagnostics.');
  console.error(error instanceof Error ? error.stack || error.message : String(error));
  process.exit(1);
});
