function requireActiveBranch(req, res, next) {
  const branchId = req.user?.activeBranchId;
  if (!branchId) return res.status(400).json({ error: "No active branch selected" });
  req.activeBranchId = branchId;
  return next();
}

function branchWhere(req, extra = {}) {
  return { branchId: req.activeBranchId, ...extra };
}

module.exports = { requireActiveBranch, branchWhere };

