import { query } from "./db.js";
export async function bumpCounter(appId, category, outcome, n = 1) {
    if (n <= 0)
        return;
    try {
        await query(`INSERT INTO send_counters (day, app_id, category, outcome, count)
       VALUES (CURRENT_DATE, $1, $2, $3, $4)
       ON CONFLICT (day, app_id, category, outcome)
       DO UPDATE SET count = send_counters.count + EXCLUDED.count`, [appId, category, outcome, n]);
    }
    catch (err) {
        console.error("[notify] counter bump failed", err);
    }
}
export async function pruneCounters() {
    try {
        await query(`DELETE FROM send_counters WHERE day < CURRENT_DATE - 90`);
    }
    catch (err) {
        console.error("[notify] counter prune failed", err);
    }
}
