const { query } = require('../../utils/db') const COLS = 'id, user_id, username, lost_address, cleared_at, acknowledged_at' // Accounts cleared by the Phase 1b de-duplication, newest first. async function list() { return query(`SELECT ${COLS} FROM email_dedupe_report ORDER BY cleared_at DESC, id DESC`) } async function countUnacknowledged() { const rows = await query('SELECT COUNT(*) AS n FROM email_dedupe_report WHERE acknowledged_at IS NULL') return Number(rows[0] ? rows[0].n : 0) } // Dismiss the whole report. Idempotent — an already-acknowledged row is skipped // so a second dismissal cannot rewrite when it happened. async function acknowledgeAll() { const res = await query('UPDATE email_dedupe_report SET acknowledged_at = NOW() WHERE acknowledged_at IS NULL') return res.affectedRows || 0 } module.exports = { list, countUnacknowledged, acknowledgeAll }