import asyncHandler from '../utils/asyncHandler.js';
import expenseService from '../services/expenseService.js';

export const list = asyncHandler(async (req, res) => {
  const data = await expenseService.listExpenses(req.query);
  res.status(200).json({ success: true, data });
});

export const create = asyncHandler(async (req, res) => {
  const expense = await expenseService.createExpense(req.body, req);
  res.status(201).json({ success: true, message: 'Expense recorded', data: { expense } });
});

export const update = asyncHandler(async (req, res) => {
  const expense = await expenseService.updateExpense(req.params.id, req.body, req);
  res.status(200).json({ success: true, message: 'Expense updated', data: { expense } });
});

export const remove = asyncHandler(async (req, res) => {
  await expenseService.deleteExpense(req.params.id, req);
  res.status(200).json({ success: true, message: 'Expense deleted' });
});
