import type { db as prodDb } from "../../../db/index.ts"; import { getAllCategories } from "../../services/category.service.ts"; import { getAllItems } from "../../services/item.service.ts"; import { getAllSetups } from "../../services/setup.service.ts"; import { getAllThreads } from "../../services/thread.service.ts"; import { getGlobalTotals } from "../../services/totals.service.ts"; type Db = typeof prodDb; export function getCollectionSummary(db: Db) { const totals = getGlobalTotals(db); const categories = getAllCategories(db); const items = getAllItems(db); const setups = getAllSetups(db); const activeThreads = getAllThreads(db, false); // Build items-by-category map const itemsByCategory: Record = {}; for (const item of items) { const catName = item.categoryName; itemsByCategory[catName] = (itemsByCategory[catName] ?? 0) + 1; } return { overview: { totalItems: totals?.itemCount ?? 0, totalWeightGrams: totals?.totalWeight ?? 0, totalCostCents: totals?.totalCost ?? 0, categoryCount: categories.length, setupCount: setups.length, activeThreadCount: activeThreads.length, }, itemsByCategory, activeThreads: activeThreads.map((t) => ({ id: t.id, name: t.name, candidateCount: t.candidateCount, category: t.categoryName, })), }; }