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

const router = express.Router();

router.get('/osm/amenities', checkPermissions('READ_PLACES'), wrapAsync(async (req, res) => {
  res.status(200).send({
    source: 'OpenStreetMap',
    amenities: GeoSeekCollectorService.supportedAmenities(),
  });
}));

router.post('/osm', checkPermissions('CREATE_PLACES'), wrapAsync(async (req, res) => {
  const payload = await GeoSeekCollectorService.collectOpenStreetMap(
    req.body || {},
    req.currentUser,
  );

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

module.exports = router;
