const express = require('express');
const router = express.Router();
const {
	getAllRestaurants,
	getRestaurant,
	restaurantSave,
	getSavedRestaurants,
	createReview,
	updateReview,
	deleteReview,
	getRestaurantReviews,
} = require('../../controllers/members/restaurants');
const { body } = require('express-validator');
const { validation, memberAuth } = require('../../middlewares');

router.get('/saves', memberAuth, getSavedRestaurants);

router.post(
	'/saves',
	memberAuth,
	[body('restaurantId').notEmpty(), body('save').isBoolean(), validation],
	restaurantSave,
);

router.get('/reviews/:id', getRestaurantReviews);

router.post(
	'/reviews',
	memberAuth,
	[body('restaurantId').notEmpty(), body('rating').isInt({ min: 1, max: 5 }), validation],
	createReview,
);

router.patch(
	'/reviews',
	memberAuth,
	[
		body('reviewId').notEmpty(),
		body('rating').isInt({
			min: 1,
			max: 5,
		}),
		validation,
	],
	updateReview,
);

router.delete('/reviews/:reviewId', memberAuth, deleteReview);

router.get('/:id', getRestaurant);
router.get('/', getAllRestaurants);

module.exports = router;
