// Copyright (c) 2020,2021, StepZen, Inc.

const generate = async (req, res) => {
  const action = req.params.action;
  const { generators, workspace } = req;

  if (generators) {
    if (action === "engines" && req.method === "GET") {
      const engines = await generators.getEngines();
      return res.json(engines);
    }

    if (action === "import" && req.method === "POST") {
      const importing = await generators.doImporting(req.body, workspace);
      return res.json(importing);
    }

    if (action === "validate" && req.method === "POST") {
      const validation = await generators.getValidation(req.body);
      return res.json(validation);
    }
  }

  res.status(404).send();
};

module.exports = generate;
