const routes = require('express').Router();

const { cacheSuccesses } = require('../../middlewares/cache');
const { isAdministratorUser, isLoggedUser } = require('../../middlewares/accessValidator');
const SchemaValidator = require('../../middlewares/schemaValidator');

//const PaginateMiddleware = require('../../middlewares/paginate');
//const FieldMiddleware = require('../../middlewares/fields');
const SortMiddleware = require('../../middlewares/sort');

const VenueValidation = require('./venue.validations');
const venueController = require('./venue.controller');

routes.get('/venues', 
    isLoggedUser,
    cacheSuccesses('24 hours'),  
    SortMiddleware.middleware({ default: "city" }), 
    venueController.find()
);

routes.get('/venues/:id', 
    isLoggedUser,
    cacheSuccesses('24 hours'), 
    venueController.findOne()
);

/*
routes.get('/venues/:id/events', 
    //isLoggedUser, 
    //SortMiddleware.middleware({ default: "name" }), 
    (req, res, next) => {
        req.params.association = 'Events';
        next();
    },
    venueController.find());

*/

routes.get('/venues/count', 
    isLoggedUser,
    cacheSuccesses('24 hours'), 
    venueController.count()
);

/********************************************************************************************************
 *  ADMINISTRACIÓN
 *********************************************************************************************************
 */

 // Nuevo
routes.post('/admin/venues/', 
    //isAdministratorUser,
    SchemaValidator(VenueValidation.VenueInputType, true), 
    venueController.create()
);

// Update
routes.put('/admin/venues/:id',
    //isAdministratorUser,
    venueController.update()
);

// Delete
routes.delete('/admin/venues/:id', 
    //isAdministratorUser, 
    venueController.delete()
);

module.exports = routes;