import { db, pool } from './db.js';

// id → image (served from the frontend /public/news folder at /news/...)
const radarImages = {
  'green-demand-growth':            '/news/photo-1551288049-bebda4e38f71.jpg',
  'stricter-green-definitions':     '/news/photo-1581092160607-ee22731c9b4e.jpg',
  'premium-willingness':            '/news/photo-1466611653911-95081537e5b7.jpg',
  'trading-value-growth':           '/news/photo-1611974789855-9c2a0a7236a3.jpg',
  'power-demand-surge':             '/news/photo-1518770660439-4636190af475.jpg',
  'digital-trading-edge':           '/news/photo-1504328345606-18bbc8c9d7d1.jpg',
  'electricity-cost-driver':        '/news/photo-1494412519320-aa613dfb7738.jpg',
  'hbi-decoupling':                 '/news/photo-1578662996442-48f60103fc96.jpg',
  'massive-asset-reconfiguration':  '/news/photo-1504307651254-35680f356dfd.jpg',
  'india-demand-doubling':          '/news/photo-1567789884554-0b844b597180.jpg',
  'scrap-shortage-crisis':          '/news/photo-1566873535350-6586b0b7a1f2.jpg',
  'china-demand-decline':           '/news/photo-1570168007204-dfb528c6958f.jpg',
};

const stmt = db.prepare('UPDATE radar_items SET img = ? WHERE id = ?');
let updated = 0;
for (const [id, img] of Object.entries(radarImages)) {
  updated += (await stmt.run(img, id)).changes;
}
console.log(`✓ radar images updated: ${updated}/${Object.keys(radarImages).length}`);

// also set the matching article cover images (for home report cards)
const articleImages = {
  'green-premia-trends':           '/news/photo-1473341304170-971dccb5ac1e.jpg',
  'commodity-trading-scurve':      '/news/photo-1611974789855-9c2a0a7236a3.jpg',
  'green-steel-hubs-pathway':      '/news/photo-1581092160607-ee22731c9b4e.jpg',
  'india-steel-growth-resilience': '/news/photo-1567789884554-0b844b597180.jpg',
};
const aStmt = db.prepare('UPDATE articles SET cover_image = ? WHERE id = ?');
let aUpdated = 0;
for (const [id, img] of Object.entries(articleImages)) {
  aUpdated += (await aStmt.run(img, id)).changes;
}
console.log(`✓ article covers updated: ${aUpdated}/${Object.keys(articleImages).length}`);

await pool.end();
