import type { Context } from "hono";
import { listExpenses } from "../expenses.service";

export async function listExpensesHandler(c: Context) {
  const status = c.req.query("status");
  const page = parseInt(c.req.query("page") ?? "1", 10);
  const pageSize = parseInt(c.req.query("pageSize") ?? "10", 10);
  const periodicExpenseId = c.req.query("periodicExpenseId");
  const search = c.req.query("search");
  const result = await listExpenses({
    status,
    page,
    pageSize,
    periodicExpenseId: periodicExpenseId ? parseInt(periodicExpenseId, 10) : undefined,
    search: search || undefined,
  });
  return c.json(result);
}
