import { Hono } from "hono";
import {
	getCategoryTotals,
	getGlobalTotals,
} from "../services/totals.service.ts";

type Env = { Variables: { db?: any; userId?: number } };

const app = new Hono<Env>();

app.get("/", async (c) => {
	const db = c.get("db");
	const userId = c.get("userId")!;
	const categoryTotals = await getCategoryTotals(db, userId);
	const globalTotals = await getGlobalTotals(db, userId);
	return c.json({ categories: categoryTotals, global: globalTotals });
});

export { app as totalRoutes };
