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

const router = express.Router();

router.post(
  '/follow-up',
  checkPermissions('CREATE_ACTIVITIES'),
  checkPermissions('UPDATE_DEALS'),
  wrapAsync(async (req, res) => {
    const payload = await SalesWorkflowService.scheduleFollowUp(
      req.body,
      req.currentUser,
    );

    res.status(200).send(payload);
  }),
);

router.use('/', require('../helpers').commonErrorHandler);

module.exports = router;
