import purchaseService from '../services/purchaseService.js';

export const getAll = async (req, res, next) => {
  try {
    const result = await purchaseService.getAllPurchases(req.query);
    res.json({ success: true, data: result });
  } catch (error) {
    next(error);
  }
};

export const getById = async (req, res, next) => {
  try {
    const purchase = await purchaseService.getPurchaseById(req.params.id);
    res.json({ success: true, data: purchase });
  } catch (error) {
    next(error);
  }
};

export const create = async (req, res, next) => {
  try {
    const purchase = await purchaseService.createPurchase(req.body, req);
    res.status(201).json({ success: true, message: 'Purchase recorded', data: purchase });
  } catch (error) {
    next(error);
  }
};
