const { checkHealth } = require("../services/storageService");
const { handleServerError } = require("../utils/helpers");

async function healthController(_req, res) {
  try {
    const health = await checkHealth();
    res.json(health);
  } catch (error) {
    handleServerError(res, error, "Failed to check health");
  }
}

function crashController(_req, res) {
  res.status(202).json({ status: "crashing", message: "Intentional unhandled exception triggered." });
  setImmediate(() => {
    throw new Error("Intentional crash from /api/crash endpoint");
  });
}

module.exports = {
  healthController,
  crashController
};
