import { useQuery } from "@tanstack/react-query";
import { apiGet } from "../lib/api";

interface CategoryTotals {
	categoryId: number;
	categoryName: string;
	categoryIcon: string;
	totalWeight: number;
	totalCost: number;
	itemCount: number;
}

interface GlobalTotals {
	totalWeight: number;
	totalCost: number;
	itemCount: number;
}

interface TotalsResponse {
	categories: CategoryTotals[];
	global: GlobalTotals;
}

export type { CategoryTotals, GlobalTotals, TotalsResponse };

export function useTotals() {
	return useQuery({
		queryKey: ["totals"],
		queryFn: () => apiGet<TotalsResponse>("/api/totals"),
	});
}
