const express = require('express');
const { body } = require('express-validator');
const { validation, memberAuth } = require('../../middlewares');
const {
	getAllActivities,
	getActivity,
	reviewActivity,
	likeActivity,
	updateReview,
	deleteReview,
	getActivityReviews,
} = require('../../controllers/members/activities');

const router = express.Router();

router.get('/', getAllActivities);
router.get('/:id', getActivity);
router.get('/:id/reviews', getActivityReviews);

router.post(
	'/review',
	memberAuth,
	[
		body('activityId').notEmpty(),
		body('guideRating').isFloat({ min: 1, max: 5 }),
		body('valueForMoneyRating').isFloat({ min: 1, max: 5 }),
		body('transportationRating').isFloat({ min: 1, max: 5 }),
		validation,
	],
	reviewActivity,
);

router.post('/like', memberAuth, [body('activityId').notEmpty(), body('like').isBoolean(), validation], likeActivity);

router.patch(
	'/review',
	memberAuth,
	[
		body('reviewId').notEmpty(),
		body('guideRating').isFloat({ min: 1, max: 5 }).optional(),
		body('valueForMoneyRating').isFloat({ min: 1, max: 5 }).optional(),
		body('transportationRating').isFloat({ min: 1, max: 5 }).optional(),
		validation,
	],
	updateReview,
);
router.delete('/review/:id', memberAuth, deleteReview);

module.exports = router;
