const db = require('./db')

function getStats() {
  const viewers = db.prepare(
    "SELECT COUNT(*) as n FROM visits WHERE last_seen > datetime('now', '-2 minutes')"
  ).get().n
  const cumulative = db.prepare('SELECT total FROM visitor_count WHERE id = 1').get()?.total ?? 0
  const feedbackCount = db.prepare('SELECT COUNT(*) as n FROM feedback').get().n ?? 0
  const shareCount = db.prepare('SELECT total FROM share_count WHERE id = 1').get()?.total ?? 0
  return { viewers, cumulative, feedbackCount, shareCount }
}

module.exports = { getStats }
