-- Kurzüberblick: Zeilen, Nutzer, Summen Ein-/Ausgang im gleichen Fenster wie
-- falukant_moneyflow_by_activity.sql (Platzhalter identisch).

SELECT
  COUNT(*)::bigint AS row_count,
  COUNT(DISTINCT m.falukant_user_id)::bigint AS distinct_falukant_users,
  ROUND(SUM(m.change_value)::numeric, 2) AS net_sum_all,
  ROUND(SUM(CASE WHEN m.change_value < 0 THEN m.change_value ELSE 0 END)::numeric, 2) AS sum_negative_only,
  ROUND(SUM(CASE WHEN m.change_value > 0 THEN m.change_value ELSE 0 END)::numeric, 2) AS sum_positive_only,
  MIN(m."time") AS first_ts,
  MAX(m."time") AS last_ts
FROM falukant_log.moneyflow m
WHERE m."time" >= NOW() - (INTERVAL '1 day' * __DIAG_DAYS__)
__DIAG_USER_FILTER__;
