const express = require('express');
const router = express.Router();
const {
  autocomplete,
  geocode,
  reverseGeocode,
  getRoute,
  getMatrix,
  suggestWaypoints,
  searchItalianCities,
  getDistance,
  getIsochrone
} = require('../controllers/geocodingController');

// Rate limiting opzionale
const rateLimit = require('express-rate-limit');

const geoLimiter = rateLimit({
  windowMs: 60 * 1000, // 1 minuto
  max: 60, // 60 richieste per minuto
  message: { success: false, message: 'Troppe richieste, riprova tra poco' }
});

router.use(geoLimiter);

// Routes
router.get('/autocomplete', autocomplete);
router.get('/geocode', geocode);
router.get('/reverse', reverseGeocode);
router.get('/route', getRoute);
router.post('/matrix', getMatrix);
router.get('/suggest-waypoints', suggestWaypoints);
router.get('/cities/it', searchItalianCities);
router.get('/distance', getDistance);
router.get('/isochrone', getIsochrone);

module.exports = router;