const express = require('express');
const StudioService = require('../services/studio');
const wrapAsync = require('../helpers').wrapAsync;
const { checkPermissions } = require('../middlewares/check-permissions');

const router = express.Router();

router.get(
  '/launchpad',
  checkPermissions('READ_PROJECTS'),
  wrapAsync(async (req, res) => {
    const payload = await StudioService.getLaunchpad(req.currentUser);
    res.status(200).send(payload);
  }),
);

router.post(
  '/launchpad',
  checkPermissions('CREATE_PROJECTS'),
  wrapAsync(async (req, res) => {
    const payload = await StudioService.createLaunchpadSession(req.body || {}, req.currentUser);
    res.status(200).send(payload);
  }),
);

module.exports = router;
