const kube = require("../services/kube.services");

async function getAlive(req, res, next) {
  try {
    var state = kube.getAlive();
    res.status((await state).code).send((await state).state);
  } catch (err) {
    res.status("503").send({ state: "error" });
  }
}

async function getReady(req, res, next) {
  try {
    res.json(await kube.getReady(req.body));
  } catch (err) {
    console.error("Unknown Error", err.message);
    next(err);
  }
}

async function getTime(req, res, next) {
  try {
    res.json(await kube.getTime(req.body));
  } catch (err) {
    console.error("Unknown Error", err.message);
    err.status = 503;
    next(err);
  }
}

module.exports = {
  getAlive,
  getReady,
  getTime,
};
