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

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

export const create = async (req, res, next) => {
  try {
    const heldBill = await heldBillService.createHeldBill(req.body, req);
    res.status(201).json({
      success: true,
      message: `Bill held as ${heldBill.holdNumber}`,
      data: heldBill,
    });
  } catch (error) {
    next(error);
  }
};

export const resume = async (req, res, next) => {
  try {
    const heldBill = await heldBillService.resumeHeldBill(req.params.id, req);
    res.json({ success: true, message: `Resumed ${heldBill.holdNumber}`, data: heldBill });
  } catch (error) {
    next(error);
  }
};

export const remove = async (req, res, next) => {
  try {
    const heldBill = await heldBillService.deleteHeldBill(req.params.id, req);
    res.json({ success: true, message: `Deleted ${heldBill.holdNumber}`, data: heldBill });
  } catch (error) {
    next(error);
  }
};
