const express = require('express');
const VortaUniverseService = require('../services/vortaUniverse');
const wrapAsync = require('../helpers').wrapAsync;

const router = express.Router();

router.get('/state', wrapAsync(async (req, res) => {
  const payload = await VortaUniverseService.getState(req.currentUser);
  res.status(200).send(payload);
}));

router.post('/state/reset', wrapAsync(async (req, res) => {
  const payload = await VortaUniverseService.resetState(req.currentUser);
  res.status(200).send(payload);
}));

router.get('/social-feed', wrapAsync(async (req, res) => {
  const payload = await VortaUniverseService.getSocialFeed(req.currentUser);
  res.status(200).send(payload);
}));

router.post('/social-feed/reset', wrapAsync(async (req, res) => {
  const payload = await VortaUniverseService.resetSocialFeed(req.currentUser);
  res.status(200).send(payload);
}));

router.post('/posts', wrapAsync(async (req, res) => {
  const payload = await VortaUniverseService.createSocialPost(req.currentUser, req.body.data || req.body || {});
  res.status(200).send(payload);
}));

router.post('/posts/:postId/comments', wrapAsync(async (req, res) => {
  const payload = await VortaUniverseService.createSocialComment(
    req.currentUser,
    req.params.postId,
    req.body.data || req.body || {},
  );
  res.status(200).send(payload);
}));

router.post('/auth/otp/request', wrapAsync(async (req, res) => {
  const payload = await VortaUniverseService.requestOtp(req.currentUser, req.body.data || req.body || {});
  res.status(200).send(payload);
}));

router.post('/auth/otp/verify', wrapAsync(async (req, res) => {
  const payload = await VortaUniverseService.verifyOtp(req.currentUser, req.body.data || req.body || {});
  res.status(200).send(payload);
}));

router.patch('/trust-score', wrapAsync(async (req, res) => {
  const payload = await VortaUniverseService.updateTrustScore(req.currentUser, req.body.data || req.body || {});
  res.status(200).send(payload);
}));

router.post('/modules/:moduleId/run', wrapAsync(async (req, res) => {
  const payload = await VortaUniverseService.runModule(req.currentUser, req.params.moduleId);
  res.status(200).send(payload);
}));

router.post('/products', wrapAsync(async (req, res) => {
  const payload = await VortaUniverseService.createProduct(req.currentUser, req.body.data || req.body || {});
  res.status(200).send(payload);
}));

router.post('/products/demo', wrapAsync(async (req, res) => {
  const payload = await VortaUniverseService.createDemoProduct(req.currentUser);
  res.status(200).send(payload);
}));

module.exports = router;
