// Script to list all emails with missing brands or missing thumbs up/down sentiment
// Usage: Run with `node scripts/list-missing-brand-or-sentiment.mjs`

import fs from 'fs';

const dbPath = '/Users/Matt/Downloads/local-db.json';
const db = JSON.parse(fs.readFileSync(dbPath, 'utf8'));

const missingBrand = [];
const missingSentiment = [];

for (const event of db.raw_email_events || []) {
  const brand = event.brand || event.document_brand || event.current_brand;
  if (!brand || brand === 'Unspecified') {
    missingBrand.push({
      sent_email_name: event.sent_email_name,
      approved_document_name: event.approved_document_name,
      brand: brand || 'Unspecified',
    });
  }
  if ((event.thumbs_up === undefined || event.thumbs_down === undefined) && !event.sentiment) {
    missingSentiment.push({
      sent_email_name: event.sent_email_name,
      approved_document_name: event.approved_document_name,
      thumbs_up: event.thumbs_up,
      thumbs_down: event.thumbs_down,
      sentiment: event.sentiment,
    });
  }
}

console.log('=== Emails with missing brand ===');
console.log(missingBrand);
console.log('Total:', missingBrand.length);

console.log('\n=== Emails with missing thumbs up/down sentiment ===');
console.log(missingSentiment);
console.log('Total:', missingSentiment.length);
