import type { Database } from 'bun:sqlite';

/**
 * Construye un mapa de grupos activos (no comunidad, no archivados) id -> nombre.
 */
export function cacheActiveGroups(db: Database): Map<string, string> {
  const map = new Map<string, string>();
  const rows = db
    .prepare('SELECT id, name FROM groups WHERE active = TRUE AND COALESCE(is_community,0) = 0 AND COALESCE(archived,0) = 0')
    .all() as Array<{ id: string; name: string | null }>;
  for (const g of rows) {
    map.set(String(g.id), String(g.name ?? ''));
  }
  return map;
}
