import PredefinedActivity from '../models/PredefinedActivity.js';
import sequelize from '../database.js';

async function check() {
  try {
    await sequelize.authenticate();
    const rows = await PredefinedActivity.findAll({ attributes: ['id', 'name', 'drawingData'] });
    const invalid = [];
    for (const r of rows) {
      const id = r.id;
      const name = r.name;
      const raw = r.drawingData;
      if (raw == null) continue;
      if (typeof raw !== 'string') {
        invalid.push({ id, name, reason: 'not-string', raw: String(raw).slice(0, 200) });
        continue;
      }
      try {
        JSON.parse(raw);
      } catch (e) {
        // If raw looks like an object literal without quotes, consider invalid
        invalid.push({ id, name, reason: 'invalid-json', error: e.message, raw: raw.slice(0, 200) });
      }
    }
    if (invalid.length === 0) {
      console.log('No invalid drawingData found.');
    } else {
      console.log('Invalid drawingData rows:');
      invalid.forEach(i => console.log(JSON.stringify(i)));
    }
  } catch (err) {
    console.error('Script error', err);
  } finally {
    await sequelize.close();
  }
}

check();
