/**
 * Dashboard summary API — single aggregation endpoint for dashboard widgets.
 *
 * GET /dashboard-summary/:space → { tasks, calendar, flows }
 *
 * Uses existing MI data functions (zero new DB queries).
 */

import { Hono } from "hono";
import { getRecentTasksForMI } from "../modules/rtasks/mod";
import { getUpcomingEventsForMI } from "../modules/rcal/mod";
import { getRecentFlowsForMI } from "../modules/rflows/mod";

const dashboardRoutes = new Hono();

dashboardRoutes.get("/dashboard-summary/:space", (c) => {
	const space = c.req.param("space");
	if (!space) return c.json({ error: "space required" }, 400);

	const tasks = getRecentTasksForMI(space, 5);
	const calendar = getUpcomingEventsForMI(space, 14, 5);
	const flows = getRecentFlowsForMI(space, 3);

	return c.json({ tasks, calendar, flows });
});

export { dashboardRoutes };
